Skip to content

[context menu] Close the open menu on Tab - #6072

Merged
atomiks merged 2 commits into
mui:masterfrom
rohits2501:fix/context-menu-shift-tab
Nov 10, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
rohits2501:fix/context-menu-shift-tab

Conversation

@rohits2501

@rohits2501 rohits2501 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6063.

Shift+Tab closed a root context menu and returned focus, but Tab did nothing. The context menu's focus manager is modal (since #3645), so its guard swallowed Tab when no item was tabbable.

Tab now closes the root context menu the same way Shift+Tab does, and focus goes back to whatever had it before the menu opened. A regular Menu already closes on both. Submenus and regular menus are unchanged.

@pkg-pr-new

pkg-pr-new Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

commit: d3a792d

@code-infra-dashboard

code-infra-dashboard Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+56B(+0.01%) 🔺+27B(+0.02%)

Details of bundle changes

Performance

No regressions in 36 benchmarks · ran 3m 09s · details


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

@netlify

netlify Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit d3a792d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6af2a3a6dd8960fb0ec27cd6
😎 Deploy Preview https://deploy-preview-6072--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.

@rohits2501

Copy link
Copy Markdown
Contributor Author

@atomiks Please review when you get some time.
Thanks!

@zannager zannager added the component: context menu Changes related to the context menu component. label Oct 27, 2026
@michaldudak

Copy link
Copy Markdown
Member

The bug is real, but the PR makes Shift+Tab match the accidental behavior instead of the deliberate one.

Where each behavior came from:

The PR description says a regular Menu has "the same split", but it doesn’t: a regular Menu closes on both Tab and Shift+Tab, with modal on or off. That is the APG menu-button behavior. So after this PR, ContextMenu would be the only menu in the library where Tab does nothing in either direction.

I'd make the Tab close the root context menu the same way Shift+Tab already does instead. Focus would go back to whatever had it before the menu opened.

@rohits2501 rohits2501 changed the title [context menu] Keep Shift+Tab inside the open menu [context menu] Close the open menu on Tab Oct 29, 2026
@rohits2501

Copy link
Copy Markdown
Contributor Author

Thanks @michaldudak, that makes sense. Reworked in de8eba2.

  • Shift+Tab is back to closing the root context menu, and the original test is restored.
  • Tab now closes the root context menu through the same path. The context menu's reference is virtual, so focus goes back to whatever had it before the menu opened.
  • Submenus and regular menus are unchanged. I also corrected the description: a regular Menu closes on both Tab and Shift+Tab.

Added returns focus to the focused surface when closing with Tab, and it fails without the change.

@rohits2501

Copy link
Copy Markdown
Contributor Author

Hi @michaldudak
Please review and help me merge this PR when you get some time.
Thanks!

@atomiks atomiks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the fix!

@atomiks atomiks added the type: bug It doesn't behave as expected. label Nov 10, 2026
Shift+Tab closed a root context menu while Tab left it open.
The root context menu's modal focus manager swallowed Tab, so only Shift+Tab closed it. Tab now closes it the same way and returns focus, as a regular menu closes on both.
@atomiks
atomiks force-pushed the fix/context-menu-shift-tab branch from de8eba2 to d3a792d Compare November 10, 2026 04:54
@atomiks
atomiks enabled auto-merge (squash) November 10, 2026 04:56
@atomiks
atomiks merged commit f57a86e into mui:master Nov 10, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[context menu] Tab is trapped in the open popup but Shift+Tab closes it and returns focus

4 participants