Skip to content

[menu] Close submenu when focus returns through its guard - #5793

Merged
jjenzz merged 14 commits into
mui:masterfrom
jjenzz:codex/menu-voiceover-submenu-return
Sep 25, 2026
Merged

jjenzz merged 14 commits into
mui:masterfrom
jjenzz:codex/menu-voiceover-submenu-return

Conversation

@jjenzz

@jjenzz jjenzz commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

The bug: On iPhone VoiceOver, moving back from an open submenu to its trigger leaves the submenu open, so moving forward enters the submenu again instead of reaching the next item in the parent menu. The screen reader user cannot continue past the trigger.

ScreenRecording_09-24-2026.16-00-40_1.mov

Note how I cannot move down to Play Next, it just keeps re-entering the submenu

The fix: Closes the submenu when focus returns to its trigger through the submenu focus guard. This applies to keyboard navigation such as Shift+Tab and is especially needed when a screen reader moves back to the trigger, so navigation can continue to the next parent menu item. The existing beforeContentFocusGuardRef is now connected for submenus, so the trigger can identify that return by comparing the focus event's relatedTarget directly with its focus guard. Hovering back to the trigger can also move focus there directly from a submenu item; that should leave the submenu open.

Tests

  • Added a regression test for returning focus to the trigger; it fails on master before the fix and passes afterward.
  • The existing Shift+Tab test now also verifies that the parent menu stays open.
  • pnpm test:jsdom MenuSubmenuTrigger --no-watch
  • pnpm test:chromium MenuSubmenuTrigger --no-watch
  • pnpm test:jsdom MenuRoot --no-watch
  • pnpm test:chromium MenuRoot --no-watch
  • pnpm typescript
  • pnpm eslint
  • pnpm prettier
  • pnpm stylelint

@pkg-pr-new

pkg-pr-new Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5793
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5793
    

commit: 98ba6cd

@code-infra-dashboard

code-infra-dashboard Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+359B(+0.08%) 🔺+109B(+0.07%)

Details of bundle changes

Performance

Total duration: 908.88 ms -3.38 ms(-0.4%) | Renders: 76 (+0) | Paint: 1,515.45 ms +11.26 ms(+0.7%)

Test Duration Renders
Checkbox mount (500 instances) 48.77 ms ▼-12.41 ms(-20.3%) 1 (+0)

14 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 98ba6cd
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ab6ae9d5205360008879dcd
😎 Deploy Preview https://deploy-preview-5793--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@jjenzz
jjenzz marked this pull request as draft September 24, 2026 14:37
@jjenzz jjenzz added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. accessibility a11y labels Sep 24, 2026
@jjenzz
jjenzz marked this pull request as ready for review September 24, 2026 15:04
@jjenzz
jjenzz force-pushed the codex/menu-voiceover-submenu-return branch from 898e75a to 1a48cb0 Compare September 24, 2026 15:07
@jjenzz
jjenzz marked this pull request as draft September 24, 2026 15:20
@jjenzz jjenzz changed the title [menu] Close submenu when focus returns to its trigger [menu] Close VO submenu when focus returns to its trigger Sep 24, 2026
@jjenzz

jjenzz commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@claude review

@github-actions

This comment was marked as resolved.

@jjenzz jjenzz changed the title [menu] Close VO submenu when focus returns to its trigger [menu] Close submenu when focus returns through its guard Sep 25, 2026
@jjenzz

jjenzz commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

Feedback responses

Thanks for the review. Here is the outcome for each feedback point:

  1. Keyboard behavior — accepted the wording and test concern; rejected VoiceOver-only gating. Shift+Tab should close the submenu while leaving the parent menu open. The source comment and PR title/description now describe the general behavior and explain why it is especially needed for screen readers. The existing Shift+Tab test now asserts that the parent menu stays open. Commit: 3cb42f475.

  2. Parent menu navigation — accepted. Both guard-return tests now include a Play Next sibling item. After the submenu closes, they assert that the parent popup remains mounted and ArrowDown reaches that item. Commit: ebfc34043.

  3. Direct trigger focus — accepted. The plain test now checks that focusing the trigger directly from a submenu item leaves the submenu open. Both the plain and shadow-root tests flush microtasks before asserting that it remains open. Commit: b4ef50bd0.

  4. Guard lookup assertion — accepted. Both assertions now use toBeTruthy(), so the test fails at the lookup when the guard is null or undefined. Commit: d293ca1f8.

  5. Focus guard ref scope — rejected. Passing beforeContentFocusGuardRef consistently through MenuPopup has no effect in variants with no current consumer. A parent-type condition would add branching for a possible future interaction without addressing a current behavior or regression. No code change.

The MenuRoot and MenuSubmenuTrigger tests pass in jsdom and Chromium. TypeScript, ESLint, Stylelint, and Prettier pass.


🤖 Feedback addressed by Codex

@jjenzz
jjenzz marked this pull request as ready for review September 25, 2026 19:30
@jjenzz
jjenzz merged commit 45a75a5 into mui:master Sep 25, 2026
24 checks passed
@jjenzz
jjenzz deleted the codex/menu-voiceover-submenu-return branch September 25, 2026 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accessibility a11y component: menu Changes related to the menu component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant