A custom FieldTemplate or WrapIfAdditionalTemplate handles propertyNamesEnum
Detect
- In your code, a custom
FieldTemplatethat rendersWrapIfAdditionalTemplateand lists the props it passes one by one instead of spreading them. - In your code, a custom
WrapIfAdditionalTemplatethat always renders a text input for the key. - In your schema, a
propertyNameswith anenum. On the rendered page, its keys still show a text input where the dropdown should be.
Change
FieldTemplateProps and WrapIfAdditionalTemplateProps have a new optional propertyNamesEnum prop.
A custom FieldTemplate that lists its props adds propertyNamesEnum to the list so the dropdown appears. It also forwards keyName so the key it renders is the real one (see FieldTemplateProps requires keyName). The rest of the props such a template forwards, hasErrors among them, are covered in Custom field, array and object templates take their error state from hasErrors.
<WrapIfAdditionalTemplate
{...otherForwardedProps}
+ keyName={keyName}
+ propertyNamesEnum={propertyNamesEnum}
>
A custom WrapIfAdditionalTemplate hands the prop to the new AdditionalPropertyKeySelect component from @rjsf/utils, which renders the theme's own SelectWidget:
{propertyNamesEnum ? (
<AdditionalPropertyKeySelect
id={additionalKeyId(id)}
label={keyLabel}
value={keyName}
propertyNamesEnum={propertyNamesEnum}
onKeyRename={onKeyRename}
disabled={disabled}
readonly={readonly}
required={required}
registry={registry}
/>
) : (
<input type='text' id={additionalKeyId(id)} onBlur={onKeyRenameBlur} defaultValue={keyName} />
)}
Verify
- A key under a
propertyNames.enumrenders as a dropdown of the allowed names, and other keys keep the text input. - A custom
ObjectFieldTemplatethat callsregistry.schemaUtils.canExpand()hides its add button once every allowed name is taken, with no change of its own.
Also read: