Skip to content

Feature : allow controls with DataForm to be set as disabled#74262

Open
Vrishabhsk wants to merge 9 commits intoWordPress:trunkfrom
Vrishabhsk:add/dataform-disabled-controls
Open

Feature : allow controls with DataForm to be set as disabled#74262
Vrishabhsk wants to merge 9 commits intoWordPress:trunkfrom
Vrishabhsk:add/dataform-disabled-controls

Conversation

@Vrishabhsk
Copy link
Contributor

What?

Closes

Why?

  • Ability to show controls in a disabled manner is not possible currently in DataForm component
  • This PR adds the ability to disable the controls by passing disabled attribute as true within respective Edit config

How?

  • Modified the types and controls to accept the disabled attribute in Edit config

Testing Instructions

  • Run npm run storybook:dev
  • Visit http://localhost:50240/?path=/story/dataviews-dataform--disabled-fields
  • Test out the disabled controls if they are working as expected.
  • Create your own variations for test cases and verify functionality

Testing Instructions for Keyboard

  • NA

Screenshots or screencast

  • NA

@github-actions
Copy link

github-actions bot commented Dec 29, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Vrishabhsk <vrishabhsk@git.wordpress.org>
Co-authored-by: oandregal <oandregal@git.wordpress.org>
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions bot added the [Package] DataViews /packages/dataviews label Dec 29, 2025
@github-actions
Copy link

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.

  • Required label: Any label starting with [Type].
  • Labels found: .

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.

@github-actions github-actions bot added the [Package] Block editor /packages/block-editor label Dec 29, 2025
@oandregal oandregal added [Type] Feature New feature to highlight in changelogs. [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond labels Jan 2, 2026
import { getValueFromObjectPath, setImmutably } from '../utils/object';
import { store as blockEditorStore } from '../store';
import { unlock } from '../lock-unlock';
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary?

@@ -0,0 +1,280 @@
/**
Copy link
Member

@oandregal oandregal Jan 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @oandregal I have added a control for disabled and removed the disabled layout entirely.

Preview

Screenshot 2026-01-07 at 6 31 45 PM

@oandregal
Copy link
Member

Im still a bit confused about the points mentioned in Considerations for implementation in the issue description. If you can add more context and a brief explanation, it would help quite a bit. Thanks
#73673 (comment)

In your PR, make the text field in the Field Types story and then open the filters. This is what happens:

Screen.Recording.2026-01-02.at.13.05.13.mov

That'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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm.. For date control I think:

  1. We use button in 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.
  2. 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.

@Vrishabhsk
Copy link
Contributor Author

Hi @oandregal I have also implemented the feature for ignoring disabled config for fields when used in Filters. I have intentionally made the Text filter disabled but from the preview you can see its still accessible.

Preview

Screenshot 2026-01-07 at 6 31 56 PM

@github-actions github-actions bot removed the [Package] Block editor /packages/block-editor label Jan 7, 2026
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.filter so filters have a dedicated control that’s derived from Edit but cannot be disabled via EditConfig.disabled:
    packages/dataviews/src/types/field-api.ts
  • Created field.filter during normalization (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 via getControlByType, 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 ),
Copy link
Contributor

@ntsekouras ntsekouras Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews [Type] Feature New feature to highlight in changelogs.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataForm: allow controls to be set as disabled

4 participants