Feature : allow controls with DataForm to be set as disabled#74262
Feature : allow controls with DataForm to be set as disabled#74262Vrishabhsk wants to merge 9 commits intoWordPress:trunkfrom
DataForm to be set as disabled#74262Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
| import { getValueFromObjectPath, setImmutably } from '../utils/object'; | ||
| import { store as blockEditorStore } from '../store'; | ||
| import { unlock } from '../lock-unlock'; | ||
| /** |
There was a problem hiding this comment.
Is this change necessary? Perhaps this PR needs a rebase from trunk?
| const fs = require( 'fs' ); | ||
| const path = require( 'path' ); | ||
|
|
||
| // eslint-disable-next-line import/no-extraneous-dependencies |
| @@ -0,0 +1,280 @@ | |||
| /** | |||
There was a problem hiding this comment.
Thanks for thinking of creating a story.
I'm thinking that it'll be best for maintainability to add a "disabled" control to the existing "Layout Regular" story. That way, every new control that is added (that should be present in the LayoutRegular story) will have to demonstrate its disabled state.
There was a problem hiding this comment.
In your PR, make the Screen.Recording.2026-01-02.at.13.05.13.movThat's what we need to solve and what I've mentioned in the issue description as implementation considerations (note the links there). We reuse the Edit component in filters (see). However, in filters, the Edit component should never be disabled. |
| isPressed={ isSelected } | ||
| size="small" | ||
| disabled={ disabled } | ||
| accessibleWhenDisabled={ false } |
There was a problem hiding this comment.
I was very surprised by this value for accessibleWhenDisabled. I think this should always be set to true. I noticed that we have the same prop set to false (in trunk) too in a couple of places in DataViews package.
@jorgefilipecosta it seems all 3 occurrences are from you. Was that intentional for some reason?
There was a problem hiding this comment.
Yah it was intentional, if the custom button is disabled I don't see any value in including in on the tab sequence/ screen readers tree, it seems better to not have accessible, it does not adds any value.
On the range control we also disable the reset button packages/components/src/range-control/index.tsx if it is disable we are not very consistent on using accessibleWhenDisabled=false, there are other cases where we could use it but given that we almost never use it I can also understand removing it in this case.
There was a problem hiding this comment.
Hm.. For date control I think:
- We use
buttonin a non-interactive element which is already kind of wrong semantically for HTML. Additionally screen readers announce it as a button, but it doesn't do anything. - We should either use another element (span, div, etc..) styles as we want, although maybe we could remove it entirely, since not having selected a preset indicates we are in 'custom', no?
For this PR, maybe it's similar to the range-control example you shared.
|
Hi @oandregal I have also implemented the feature for ignoring disabled config for fields when used in Filters. I have intentionally made the Preview
|
| const field = useMemo( () => { | ||
| const currentField = fields.find( ( f ) => f.id === filter.field ); | ||
| if ( currentField ) { | ||
| // For filters, we need to ensure the Edit control is never disabled. |
There was a problem hiding this comment.
This approach is not sustainable. It's replicating the logic available in getControl (see) and it also misses some things (EditConfig).
Can you think of alternatives?
We could explore any of the two I already shared under "Considerations for implementation" in the issue description.
There was a problem hiding this comment.
Hi @oandregal I felt the first point to be more robust since it segregates the Edit for filter. I have implemented the same.
Changes
- Added
NormalizedField.filterso filters have a dedicated control that’s derived fromEditbut cannot be disabled viaEditConfig.disabled:
packages/dataviews/src/types/field-api.ts - Created
field.filterduringnormalization(strip disabled from EditConfig before it becomes a closure-captured component):
packages/dataviews/src/field-types/index.tsx - Updated filters UI to use
field.filter(instead of re-deriving a base control viagetControlByType, which could drop other EditConfig options like prefix/suffix/rows):
packages/dataviews/src/components/dataviews-filters/input-widget.tsx
| type: fieldType.type, | ||
| render: field.render ?? fieldType.render, | ||
| Edit: getControl( field, fieldType.Edit ), | ||
| filter: getFilterControl( field, fieldType.Edit ), |
There was a problem hiding this comment.
Since #74733 filter prop is used similarly to sort and contains implementations of filtering logic for operators. Besides that, it doesn't feel semantically correct to me, to name it filter here.
Said that, I find the disabled prop very similar to the readOnly field and maybe a simpler approach would be to add disabled as a top-level field prop. That way we can update the controls by extracting the value from the field.disabled and for filters where we need to recreate the field we would set disabled: false, // Filters should never be disabled. here.
What do you think @oandregal ?


What?
Closes
disabled#73673disabledattribute within fieldsEditconfig used byDataFormcomponentWhy?
DataFormcomponentdisabledattribute astruewithin respectiveEditconfigHow?
disabledattribute inEditconfigTesting Instructions
npm run storybook:devhttp://localhost:50240/?path=/story/dataviews-dataform--disabled-fieldsTesting Instructions for Keyboard
Screenshots or screencast