Skip to content

Commit 3169904

Browse files
authored
fix: ArrayAsMultiSelect should pass items UI schema when retrieving enumOptions (#4955) (#4961)
1 parent 1dc946a commit 3169904

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ it according to semantic versioning. For example, if your PR adds a breaking cha
1515
should change the heading of the (upcoming) version to include a major version bump.
1616
1717
-->
18+
19+
# 6.3.2
20+
21+
## @rjsf/core
22+
23+
- Updated multi-select ArrayFields to properly use the `items` uiSchema for enumerated options, fixing [#4955](https://github.com/rjsf-team/react-jsonschema-form/issues/4955)
24+
1825
# 6.3.1
1926

2027
## Dev / docs / playground
@@ -80,7 +87,7 @@ should change the heading of the (upcoming) version to include a major version b
8087

8188
## @rjsf/mui
8289

83-
- Updated `BaseInputTemplate` to properly handle `slotProps` and `InputProps` (deprecated by MUI) with existing `endAdornment`s when the `allowClearTextInputs` flag is true, fixing [#4938](https://github.com/rjsf-team/react-jsonschema-form/issues/4938)
90+
- Updated `BaseInputTemplate` to properly handle `slotProps` and `InputProps` (deprecated by MUI) with existing `endAdornment`s when the `allowClearTextInputs` flag is true, fixing [#4938](https://github.com/rjsf-team/react-jsonschema-form/issues/4938)
8491

8592
## Dev / docs / playground
8693

packages/core/src/components/fields/ArrayField.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ function ArrayAsMultiSelect<T = any, S extends StrictRJSFSchema = RJSFSchema, F
199199
} = props;
200200
const { widgets, schemaUtils, globalFormOptions, globalUiOptions } = registry;
201201
const itemsSchema = schemaUtils.retrieveSchema(schema.items as S, items);
202-
const enumOptions = optionsList<T[], S, F>(itemsSchema, uiSchema);
202+
const itemsUiSchema = (uiSchema?.items ?? {}) as UiSchema<T[], S, F>;
203+
const enumOptions = optionsList<T[], S, F>(itemsSchema, itemsUiSchema);
203204
const { widget = 'select', title: uiTitle, ...options } = getUiOptions<T[], S, F>(uiSchema, globalUiOptions);
204205
const Widget = getWidget<T[], S, F>(schema, widget, widgets);
205206
const label = uiTitle ?? schema.title ?? name;

packages/core/test/ArrayField.test.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,6 +1345,30 @@ describe('ArrayField', () => {
13451345

13461346
expect(node.querySelector("option[value='1']")).toBeDisabled(); // use index
13471347
});
1348+
1349+
it('should use ui:enumNames from items uiSchema as option labels', () => {
1350+
const enumSchema: RJSFSchema = {
1351+
title: 'Demo',
1352+
type: 'array',
1353+
items: {
1354+
type: 'integer',
1355+
enum: [1, 2, 3],
1356+
},
1357+
uniqueItems: true,
1358+
};
1359+
const enumUiSchema: UiSchema = {
1360+
items: {
1361+
'ui:enumNames': ['A', 'B', 'C'],
1362+
},
1363+
};
1364+
const { node } = createFormComponent({ schema: enumSchema, uiSchema: enumUiSchema });
1365+
1366+
const options = node.querySelectorAll('select option');
1367+
expect(options).toHaveLength(3);
1368+
expect(options[0]).toHaveTextContent('A');
1369+
expect(options[1]).toHaveTextContent('B');
1370+
expect(options[2]).toHaveTextContent('C');
1371+
});
13481372
});
13491373

13501374
describe('CheckboxesWidget', () => {

0 commit comments

Comments
 (0)