diff --git a/packages/core/src/util/renderer.ts b/packages/core/src/util/renderer.ts index 0066286207..75773e472d 100644 --- a/packages/core/src/util/renderer.ts +++ b/packages/core/src/util/renderer.ts @@ -78,6 +78,7 @@ import { arrayDefaultTranslations, ArrayTranslations, } from '../i18n/arrayTranslations'; +import { resolveSchema } from './resolvers'; const isRequired = ( schema: JsonSchema, @@ -617,7 +618,11 @@ export const mapStateToMultiEnumControlProps = ( ownProps: OwnPropsOfControl & OwnPropsOfEnum ): StatePropsOfControl & OwnPropsOfEnum => { const props: StatePropsOfControl = mapStateToControlProps(state, ownProps); - const items = props.schema.items as JsonSchema; + let items = props.schema.items as JsonSchema; + items = + items && items.$ref + ? resolveSchema(props.rootSchema, items.$ref, props.rootSchema) + : items; const options: EnumOption[] = ownProps.options || (items?.oneOf && diff --git a/packages/core/test/util/renderer.test.ts b/packages/core/test/util/renderer.test.ts index bb0f489e33..1442f1040e 100644 --- a/packages/core/test/util/renderer.test.ts +++ b/packages/core/test/util/renderer.test.ts @@ -983,6 +983,50 @@ test('mapStateToMultiEnumControlProps - enum items', (t) => { ]); }); +test('mapStateToMultiEnumControlProps - enum with ref', (t) => { + const uischema: ControlElement = { + type: 'Control', + scope: '#/properties/colors', + }; + const state = { + jsonforms: { + core: { + schema: { + definitions: { + colors: { + type: 'string', + enum: ['red', 'green', 'pink'], + }, + }, + type: 'object', + properties: { + colors: { + type: 'array', + items: { + $ref: '#/definitions/colors', + }, + uniqueItems: true, + }, + }, + }, + data: {}, + uischema, + errors: [] as ErrorObject[], + }, + }, + }; + const ownProps = { + uischema, + path: 'colors', + }; + const props = mapStateToMultiEnumControlProps(state, ownProps); + t.deepEqual(props.options, [ + { label: 'red', value: 'red' }, + { label: 'green', value: 'green' }, + { label: 'pink', value: 'pink' }, + ]); +}); + test('mapDispatchToMultiEnumProps - enum schema - addItem', (t) => { const uischema: ControlElement = { type: 'Control', diff --git a/packages/material-renderers/src/complex/MaterialEnumArrayRenderer.tsx b/packages/material-renderers/src/complex/MaterialEnumArrayRenderer.tsx index d42120ea35..50d362ba2d 100644 --- a/packages/material-renderers/src/complex/MaterialEnumArrayRenderer.tsx +++ b/packages/material-renderers/src/complex/MaterialEnumArrayRenderer.tsx @@ -8,6 +8,7 @@ import { Paths, RankedTester, rankWith, + resolveSchema, schemaMatches, schemaSubPathMatches, uiTypeIs, @@ -99,8 +100,11 @@ export const materialEnumArrayRendererTester: RankedTester = rankWith( !Array.isArray(schema.items) && schema.uniqueItems === true ), - schemaSubPathMatches('items', (schema) => { - return hasOneOfItems(schema) || hasEnumItems(schema); + schemaSubPathMatches('items', (schema, rootSchema) => { + const resolvedSchema = schema.$ref + ? resolveSchema(rootSchema, schema.$ref, rootSchema) + : schema; + return hasOneOfItems(resolvedSchema) || hasEnumItems(resolvedSchema); }) ) )