Skip to content

[menu] Fix nested menus without a root trigger - #5645

Merged
michaldudak merged 1 commit into
mui:masterfrom
LukasTy:codex/fix-triggerless-nested-menu
Sep 9, 2026
Merged

michaldudak merged 1 commit into
mui:masterfrom
LukasTy:codex/fix-triggerless-nested-menu

Conversation

@LukasTy

@LukasTy LukasTy commented Sep 8, 2026

Copy link
Copy Markdown
Member

When a root menu has no Menu.Trigger, opening its first submenu closes the root with reason sibling-open. The root has no floating node ID, so the submenu has no parent ID and appears to be a sibling. This affects menus opened through a controlled external anchor, including the integration in mui/material-ui#48823.

Let the root supply its tree IDs when there is no active trigger. Read the store in the layout effect because a trigger can register after render and before that effect. Subscribe to the active trigger element so the effect also responds to trigger changes.

Add 11 Base UI tests for root survival, Escape and focus return, LTR and RTL, kept-mounted roots, external anchors, reopening, item selection, sibling closing on click and hover, initially open submenus, and real trigger registration. The registration tests check the IDs in the same layout pass.

Validation:

  • Nine tests fail on unchanged master; all 11 pass with the fix in Chromium and jsdom.
  • The registration test fails if the store read is replaced with the render value.
  • Menu, Context Menu, Navigation Menu, and Menubar suites: 1,074 passed and 50 skipped in Chromium; 894 passed and 230 skipped in jsdom.
  • TypeScript, ESLint, Stylelint, and formatting pass.
  • pnpm valelint reports one existing error in CONTRIBUTING.md:169: use jsdom instead of JSDOM. This PR does not change that file.

Related: #5344 was closed and proposed an event filter. This change supplies the missing IDs instead. #5641 concerns shared trigger ownership and does not change this menu ID path.

@LukasTy LukasTy added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. labels Sep 8, 2026
@pkg-pr-new

pkg-pr-new Bot commented Sep 8, 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@5645
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5645
    

commit: 6b519d6

@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+39B(+0.01%) 🔺+12B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,240.94 ms +177.87 ms(+16.7%) | Renders: 76 (+0) | Paint: 1,997.02 ms +284.13 ms(+16.6%)

Test Duration Renders
Checkbox mount (500 instances) 103.27 ms 🔺+41.65 ms(+67.6%) 1 (+0)
Select mount (200 instances) 170.92 ms 🔺+28.80 ms(+20.3%) 3 (+0)
Scroll Area mount (300 instances) 82.73 ms 🔺+18.79 ms(+29.4%) 3 (+0)
Dialog mount (300 instances) 29.17 ms 🔺+6.44 ms(+28.4%) 1 (+0)
Popover mount (300 instances) 45.03 ms +7.25 ms(+19.2%) 1 (+0)

10 tests within noise — details

Metric alarms

Test Metric Change
Checkbox mount (500 instances) bench:paint 🔺 +52.58 ms
Select mount (200 instances) bench:paint 🔺 +43.23 ms
Scroll Area mount (300 instances) bench:paint 🔺 +24.40 ms
Dialog mount (300 instances) bench:paint 🔺 +12.92 ms
Popover mount (300 instances) bench:paint 🔺 +16.74 ms

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

@netlify

netlify Bot commented Sep 8, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

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

@michaldudak michaldudak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the fix!

@michaldudak
michaldudak merged commit 5dd6ba5 into mui:master Sep 9, 2026
24 of 25 checks passed
@LukasTy
LukasTy deleted the codex/fix-triggerless-nested-menu branch September 9, 2026 09:04
mariomile added a commit to mariomile/Kore that referenced this pull request Sep 16, 2026
* fix: keep the block menu open when hovering Turn into

Base UI 1.7.0 never registers a floating node id for a root menu that has
no Menu.Trigger, so the block-handle menu (opened on a virtual anchor)
treated its own Turn into submenu as a sibling and closed itself with
reason sibling-open. Backport mui/base-ui#5645 as a pnpm patch until a
release ships it, and cover the gesture with a browser test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

* fix: never reveal the source of a rendered collection fence

The fence source appeared above the Collection widget whenever the caret
entered the code block. Hide the source for rendered fences and keep the
caret out of them: an appendTransaction guard jumps the selection past
the fence in its direction of travel, selecting the block when there is
no text on that side.

Co-Authored-By: Claude Fable 5.1 <[email protected]>

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants