-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
Related https://href.li/?https://github.com/WordPress/gutenberg/issues/73076
What problem does this address?
We have a way to set a field as "readOnly" which means that the field will use the render method in situations where the Edit one would have been used instead. For example, a text field set as readOnly will not display a input component in DataForm, but rather the result of computing its render function.
In addition to permanent non-editable fields, we also have the need for situational-non-editable fields. These fields should display disabled form controls.
What is your proposed solution?
Leverage the Edit config for field authors to be able to set a control as disabled.
Examples
A field that displays a disabled input control:
{
type: 'text',
Edit: {
control: 'input',
disabled: true
}
}A field that displays "hello, world!":
{
type: 'text',
Edit: {
control: 'input',
disabled: true
},
readOnly: true,
render: () => "Hello, world"
}Considerations for implementation
The Edit components are also used by the filters. In that scenario, there's no need to display a control as disabled. How do we handle that?
- We cannot pass a new Edit config for filters because there's no one at that point. The NormalizeField we operate with has a control. See InputWidget component takes the field and prepares is (disables validation, etc.), and how getControl works. Perhaps we can make the EditConfig.disable a separate prop of the Edit component? There's already a
operatorprop that is only used in "filter mode" (ref). - Add a new
filterprop in NormalizedFields that is created from Edit but removes the EditConfig.disabled config before creating the component.