Repository navigation
[menu] Fix submenu item VoiceOver announcement when opened by keyboard - #5067
mj12albert wants to merge 5 commits into
Conversation
commit: |
Bundle size
PerformanceTotal duration: 1,413.96 ms +106.87 ms(+8.2%) | Renders: 78 (+0)
10 tests within noise — details Metric alarms
Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
9007ec3 to
90577f8
Compare
| // omitted here so attribute-disabled items (`disabled`/`aria-disabled`) are skipped | ||
| // on open even when the consumer passes an empty `disabledIndices` array. Passing it | ||
| // would regress that behavior (see mui/base-ui#2604). | ||
| // macOS Safari VoiceOver can miss this first focus event as a freshly mounted |
There was a problem hiding this comment.
Delaying the ARIA attrs in the menu fixes the issue fully for Chrome, but without this part Safari still skips the submenu item item on the very first open (a subsequent close and reopen of the submenu works)
atomiks
left a comment
There was a problem hiding this comment.
PR review
This is a focused VoiceOver fix: it delays the submenu's initial DOM focus by an extra frame on macOS Safari (platform-gated) and defers the trigger↔popup ARIA relationship while a keyboard-opened submenu is active. The focus-delay path is correctly confined to macOS/WebKit/VoiceOver, so it can't regress other platforms. Nothing is merge-blocking. The one thing worth a second look is that the ARIA deferral is not platform-scoped — unlike the focus delay, it changes the accessibility tree for every browser and screen reader. All menu tests pass locally (808 passed).
Bugs (1)
1. 🟡 ARIA deferral applies to all screen readers, not just the targeted VoiceOver case
Location: packages/react/src/menu/submenu-trigger/MenuSubmenuTrigger.tsx:175 and packages/react/src/menu/root/MenuRoot.tsx:472
// MenuSubmenuTrigger.tsx
'aria-controls':
open && lastOpenChangeReason === REASONS.listNavigation ? undefined : popupId,
'aria-expanded':
open && lastOpenChangeReason === REASONS.listNavigation
? false
: rootTriggerProps['aria-expanded'],// MenuRoot.tsx
'aria-labelledby':
parent.type === 'menu' && open && lastOpenChangeReason === REASONS.listNavigation
? undefined
: activeTriggerElement?.id,The focus delay in useListNavigation.ts is carefully gated to platform.os.mac && …voiceOver && …webkit, but this ARIA deferral has no platform gate. Whenever a submenu is opened by keyboard, on any platform/browser/AT (NVDA, JAWS, Orca, Chrome, Firefox), and for the entire time it stays open (the condition keys off lastOpenChangeReason, which doesn't change while open — the second new test asserts it stays deferred even after focus enters the submenu), the result is:
- the open submenu's trigger reports
aria-expanded="false"and dropsaria-controls, and - the submenu popup (
role="menu") drops itsaria-labelledby, so it has no accessible name.
The most concrete consequence: a keyboard-opened submenu has no accessible name, while a click-opened one keeps aria-labelledby (the third new test encodes exactly this divergence). That's an inconsistency every screen reader sees, even though the PR description notes the original bug "doesn't occur with NVDA" — i.e. NVDA worked before this change.
Gating the ARIA deferral to the same platform.os.mac && …voiceOver && …webkit condition is feasible and carries no SSR/hydration risk: these flags are module-level constants (false on the server), and the deferral only ever activates after a client interaction (open && lastOpenChangeReason === listNavigation), never during the initial render of a closed submenu — so server and first client render agree regardless.
Failure scenario: An NVDA/JAWS user opens a submenu with ArrowRight. Before this PR the submenu announced its name (from the trigger) and the trigger reported expanded; now the submenu is unnamed and the trigger reports collapsed while open.
Fix: Either scope the three ARIA overrides behind the same platform predicate used for the focus delay (extract it to a shared constant so the two stay in sync), or, if the cross-AT behavior is intentional and was validated against NVDA/JAWS, leave a comment recording that decision.
Tests (1)
1. ℹ️ The core focus-delay fix has no automated coverage
Location: packages/react/src/menu/submenu-trigger/MenuSubmenuTrigger.test.tsx
The three new tests exercise the (non-platform-gated) ARIA deferral, which is good. But the actual subject of the PR — the two-frame delayInitialFocusRef → delayFocusFrame focus delay in useListNavigation.ts — is unreachable in jsdom because platform.os.mac/webkit/voiceOver are all false there, so shouldDelayInitialFocus is never true under test.
Failure scenario: A future refactor of the focusItem delay machinery (e.g. dropping the latestOpenRef guard in the delayFocusFrame callback, or the close-path delayFocusFrame.cancel()) would pass CI while silently breaking the VoiceOver fix.
Fix: This is inherently hard to assert without the real platform, so a unit test may not be practical — but consider noting it as a manual/VoiceOver-only verification step, or factoring the platform predicate so the delay branch can be unit-tested with the flags stubbed.
Simplifications (1)
1. ℹ️ platform.screenReader.voiceOver is redundant alongside platform.os.mac
Location: packages/react/src/floating-ui-react/hooks/useListNavigation.ts
delayInitialFocusRef.current =
platform.os.mac &&
platform.screenReader.voiceOver && // voiceOver === apple === (mac || ios)
platform.engine.webkit &&
...voiceOver is defined as apple (mac || ios) in screen-reader.ts, so once platform.os.mac is required the voiceOver term is always true and adds nothing at runtime. platform.engine.webkit && platform.os.mac already is "Safari on macOS" (the only WebKit on mac), where VoiceOver is the only screen reader — so the term can simply be dropped. It does read as intent-documenting, and the comment above already states the VoiceOver intent, so this is optional.
Docs (0)
No findings.
Verdict
Approve after nits — no correctness regressions, but the ARIA deferral's unscoped reach across all screen readers (Bug 1) is worth gating or explicitly confirming before merge.
9b2ea14 to
64b0fac
Compare
64b0fac to
44dc69f
Compare
44dc69f to
c6b58d7
Compare
PR reviewNothing merge-blocking, and the fix's structure is sound — but the diff ships two independent workarounds (the WebKit focus delay and the menu-side ARIA deferral) plus two new util files, and most of the +200 gzip can be recovered: the menu side re-implements keyboard-click detection that already exists in the store as Bugs (2)1. 🟡 ARIA relationship stays wrong for the entire lifetime of a keyboard-opened submenu, for all macOS usersLocation: macVoiceOverKeyboardOpen
? {
'aria-controls': undefined,
'aria-expanded': false,
}
Failure scenario: A VoiceOver user opens a submenu with ArrowRight, browses it, then navigates back to the trigger (VO+Left) while it's still open — VO announces the trigger as collapsed/unexpanded with no controls relationship. Same degraded semantics for any other mac AT, with VoiceOver not even running. Fix: Restore the attributes once initial focus has settled in the submenu (e.g. after the same frame window the hook fix uses), if that doesn't re-trigger the announcement bug. If it does, keep the current behavior but document the tradeoff (see Docs No. 1). 2. ℹ️ Inconsistent
|
|
this has been addressed in #5342 |
Fixes a bug where VoiceOver (reproed with Chrome & Safari) doesn't announce the initially focused submenu item when the submenu opens via keyboard (arrow keys, enter space), recording:
submenu-voiceover-bug.mov
With the fix:
fix.mov
This doesn't occur with NVDA