[menu] Implement WCAG-compliant focus management for disabled items - #2573
[menu] Implement WCAG-compliant focus management for disabled items#2573Ch-Valentine wants to merge 1 commit into
Conversation
…d items - Add disabled indices tracking to MenuRoot - Update MenuItem to register disabled state - Add focus management tests for keyboard navigation - Ensure disabled items are skipped during arrow key navigation - Follow WCAG 2.1.1 (Keyboard) and WCAG 2.4.3 (Focus Order) guidelines
commit: |
Bundle size report
|
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Demo with a focus management problem BEFORE my changes: https://codesandbox.io/p/sandbox/intelligent-dew-gxwsrp |
|
@Ch-Valentine the menubar pattern mentions disabled items should be focusable. Screen readers announce them as In macOS, when using VoiceOver, they don't get skipped; while without VoiceOver, they do. This distinction not being as feasible to check on the web may be why the recommendation always recommends focusing disabled items.
As for skipping the first disabled items when first opening, that may be correct regardless, though I am not positive
|
|
@atomiks thanks for the answer! Hm, that make sense as well) Should I close the PR ? |
|
@Ch-Valentine it seems it should be skipping the first disabled items when first opening, but still allow them be navigated to with arrow keys afterwards based on the recommendation for menubar items This issue highlights a somewhat related issue for tabs: #2098 |
|
This discussion reminds me of the |
|
I addressed this in Discord recently. Some stuff from ARIA docs from my Discord post. "There are some contexts where it is common for disabled elements to be focusable, especially inside of composite widgets. For example, as demonstrated in the menu and menubar pattern, disabled items are focusable when navigating through a menu with the arrow keys." https://www.w3.org/WAI/ARIA/apg/practices/keyboard-interface/#kbd_disabled_controls I'll close this PR since it would be a mistake. Imo, making it configurable would be a mistake too. But yes @Ch-Valentine @atomiks it does seem we should be be skipping the first disabled items when first opening. I guess this should be implemented across many components. |
|
What the other libraries seem to do:
So on those benchmarks, there is a clear skew in favor of not focusable. And on our side, we get user pressure in this same direction, by chronological order: |



Summary
Implements proper focus management for disabled menu items according to WCAG accessibility guidelines.
This is related to #1733.
Changes
disabledIndicesstate tracking and passed touseListNavigationWCAG Compliance
Testing