Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly assign label prop for MultiSelect ArrayField #2459

Merged
merged 7 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/core/src/components/fields/ArrayField.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,17 +539,18 @@ class ArrayField extends Component {
disabled,
readonly,
required,
label,
placeholder,
autofocus,
onBlur,
onFocus,
registry = getDefaultRegistry(),
rawErrors,
name,
} = this.props;
const items = this.props.formData;
const { widgets, rootSchema, formContext } = registry;
const itemsSchema = retrieveSchema(schema.items, rootSchema, formData);
const title = schema.title || name;
const enumOptions = optionsList(itemsSchema);
const { widget = "select", ...options } = {
...getUiOptions(uiSchema),
Expand All @@ -570,7 +571,7 @@ class ArrayField extends Component {
disabled={disabled}
readonly={readonly}
required={required}
label={label}
label={title}
placeholder={placeholder}
formContext={formContext}
autofocus={autofocus}
Expand Down
14 changes: 14 additions & 0 deletions packages/core/test/ArrayField_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1190,6 +1190,20 @@ describe("ArrayField", () => {
"should NOT have duplicate items (items ## 1 and 0 are identical)"
);
});

it("should pass a label as prop to custom widgets", () => {
const LabelComponent = ({ label }) => <div id="test">{label}</div>;
const { node } = createFormComponent({
schema,
widgets: {
SelectWidget: LabelComponent,
},
});

const matches = node.querySelectorAll("#test");
expect(matches).to.have.length.of(1);
expect(matches[0].textContent).to.eql(schema.title);
});
});

describe("CheckboxesWidget", () => {
Expand Down