-
Notifications
You must be signed in to change notification settings - Fork 4.6k
MenuItem: make accessible when disabled #71251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
| role={ role } | ||
| icon={ iconPosition === 'left' ? icon : undefined } | ||
| className={ className } | ||
| accessibleWhenDisabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, the bug fixed by this PR doesn't occur when using DropdownMenu's controls prop (as opposed to using the children prop).
That is because DropdownMenu internally doesn't use MenuItem when mapping over the controls prop, but uses the Button component directly and sets the accessibleWhenDisabled prop already:
gutenberg/packages/components/src/dropdown-menu/index.tsx
Lines 205 to 209 in 15bff41
| accessibleWhenDisabled | |
| disabled={ control.isDisabled } | |
| > | |
| { control.title } | |
| </Button> |
I would typically work on refactoring DropdownMenu to use MenuItem internally, but it's probably not worth it given that we already have a newer Menu component, and the upcoming DS effort
| role={ role } | ||
| icon={ iconPosition === 'left' ? icon : undefined } | ||
| className={ className } | ||
| accessibleWhenDisabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is accessibleWhenDisabled something that we want to keep optional for MenuItem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so — since MenuItem is supposed to be part of a Menu (and therefore, a composite widget), it makes sense for it to be always accessible when disabled (ie. focusable + aria-disabled attribute + no-op on click events).
Moreover, this change aligns with other menu impementations:
- the
DropdownMenucomponent already setsaccessibleWhenDisabledinternally when using thecontrolsprop instead ofchildren(see this comment); - other established component libraries, such as Ariakit and Base UI, also apply the same treatment (ie. focusable +
aria-disabledattribute + no-op on click events) to their disabled menu items; - inherently, the new (experimental)
Menucomponent also behaves the same way
In short, I don't think consumers should (or would) set a menu item as non-accessible while disabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for confirming 👍
|
Size Change: -34 B (0%) Total Size: 1.92 MB
ℹ️ View Unchanged
|
tyxla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
* MenuItem: make accessible when disabled * CHANGELOG * Update tests to account for different way to disable menu item
What?
Allow
MenuItemto be accessible (focusable) even when disabled.Why?
This prevents a bug in
DropdownMenuwhere the whole menu would become inaccessible (ie. no keyboard interactions, no close on click outside) if all the menu items are disabled.How?
By adding the
accessibleWhenDisabledprop onMenuItem's internalButtoncomponent.Testing Instructions
MenuItemof aDropdownMenuas disabledScreenshots or screencast
Kapture.2025-08-19.at.17.19.46.mp4
Kapture.2025-08-19.at.17.10.01.mp4