Changelog
- Fixes #250: Add support for custom widget options. (#252)
Breaking changes
The options
prop passed to your custom widget can now be used for any purpose, and not only the list of options (label
and value
) for enum fields. This latter list of options is now passed in an enumOptions
property in the options
prop.
That means that if you have code like this:
const schema = {
type: "string",
enum: ["foo", "bar"],
};
function MyCustomWidget(props) {
const {options} ⁼ props; // Previously, the list of enum options was passed straight away
return (
<select>{
options.map(({label, value}, i) => {
return <option key={i} value={value}>{label}</option>;
})
}</select>
);
}
const uiSchema = {
"ui:widget": MyCustomWidget
};
You need to upgrade it to:
const schema = {
type: "string",
enum: ["foo", "bar"],
};
function MyCustomWidget(props) {
const {options} ⁼ props;
const {enumOptions} = options; // The list of options is now one level deeper
return (
<select>{
enumOptions.map(({label, value}, i) => {
return <option key={i} value={value}>{label}</option>;
})
}</select>
);
}
const uiSchema = {
"ui:widget": MyCustomWidget
};