Skip to content

Commit

Permalink
Properly assign label prop for MultiSelect ArrayField (#2459)
Browse files Browse the repository at this point in the history
* Assign name prop as widget label

* Use title instead of name

* Test label prop for custom MultiSelect widgets

* Update for consistency with renderNormalArray()

* fix for consistency

Co-authored-by: Ashwin Ramaswami <aramaswamis@gmail.com>
  • Loading branch information
Parnswir and epicfaace authored Aug 11, 2021
1 parent 57fb494 commit 1bbd0ad
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 1bbd0ad

Please sign in to comment.