An extra key renders as a dropdown when propertyNames has an enum
Detect
- In your schema, an object with
additionalPropertiesorpatternPropertieswhosepropertyNameshas anenumof key names:
import { RJSFSchema } from '@rjsf/utils';
const schema: RJSFSchema = {
type: 'object',
additionalProperties: { type: 'boolean' },
propertyNames: { enum: ['darkMode', 'betaBanner', 'offlineCache'] },
};
- In your tests or CSS, selectors that find the key's text input. In every theme the rendered page now shows a select there.
Change
Update tests and styles to work with the select. A name another key already holds is left out of its options, and the add button creates the new property under the first allowed name that is still free instead of newKey, so update tests that expect newKey.
Verify
- Each key shows as a dropdown of the allowed names that aren't taken.
- The add button disappears once every allowed name is taken, the way it does at the
maxPropertieslimit. A customObjectFieldTemplatethat callsregistry.schemaUtils.canExpand()gets this on its own (see A custom ObjectFieldTemplate calls registry.schemaUtils.canExpand). - A
propertyNameswithout anenum, such as one with apattern, still renders the free-text input. - A custom
FieldTemplateorWrapIfAdditionalTemplatemay need changes for the dropdown to appear: see A custom FieldTemplate or WrapIfAdditionalTemplate handles propertyNamesEnum.
Also read: