Skip to content

[menu] Open submenus on hover after a plain delay - #4990

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/menu-submenu-hover-plain-delay
Jun 9, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:codex/menu-submenu-hover-plain-delay

Conversation

@atomiks

@atomiks atomiks commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Submenus that open on hover used to wait for the cursor to stop moving before opening, but only when the submenu trigger was the first item you reached after opening the menu with the keyboard or programmatically. In every other case they opened after a plain delay. They now always use a plain delay.

Root cause

While allowMouseEnter was still false, the submenu's hover delay was set to 0, which made the open fall back to a rest-only path (restMs) that waits for the pointer to come to rest instead of using the delay.

Changes

  • Always pass a plain open delay for submenu hover and gate it on allowMouseEnter through the hover hook's shouldOpen check, which is re-evaluated when the delay elapses.
  • Skip the gate when the delay is 0, since that opens synchronously and has no later re-check to fall back on.
  • Add a test for opening a submenu on hover after a plain delay without the pointer resting.

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

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

commit: a994fd2

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

Bundle size

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

Details of bundle changes

Performance

Total duration: 1,341.53 ms +105.98 ms(+8.6%) | Renders: 50 (+0) | Paint: 2,028.07 ms +170.10 ms(+9.2%)

Test Duration Renders
Scroll Area mount (300 instances) 100.24 ms 🔺+16.78 ms(+20.1%) 3 (+0)
Menu open (500 items) 82.97 ms 🔺+16.26 ms(+24.4%) 12 (+0)

10 tests within noise — details


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

@atomiks
atomiks force-pushed the codex/menu-submenu-hover-plain-delay branch from 72694d1 to 76f4750 Compare June 9, 2026 12:42
@atomiks
atomiks marked this pull request as ready for review June 9, 2026 12:46
@atomiks
atomiks requested a review from Copilot June 9, 2026 12:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes inconsistent submenu hover-open behavior in the React Menu implementation by ensuring submenus always open after a plain delay (instead of sometimes requiring the pointer to come to rest) when the menu was opened via keyboard/programmatic means and allowMouseEnter initially starts as false.

Changes:

  • Update MenuSubmenuTrigger to always use a plain { open, close } delay for hover, and gate the open via shouldOpen using parentMenuStore.select('allowMouseEnter') (only when delay > 0).
  • Add a regression test that verifies a submenu opens after the configured delay even while the pointer continues moving (i.e. without entering the “rest-only” path).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/react/src/menu/submenu-trigger/MenuSubmenuTrigger.tsx Ensures submenu hover-open uses a plain delay consistently and gates open via shouldOpen instead of switching to a rest-only path when allowMouseEnter is initially false.
packages/react/src/menu/root/MenuRoot.test.tsx Adds coverage for opening a submenu after a plain delay without requiring the pointer to stop moving.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@netlify

netlify Bot commented Jun 9, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

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

@netlify

netlify Bot commented Jun 9, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

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

@atomiks

atomiks commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Review (Claude Fable 5): #4990 — [menu] Open submenus on hover after a plain delay

Verdict: LGTM. The fix is sound, minimal (+34/−2), and I verified the test coverage empirically: the new test passes on the PR head and fails when the source fix is reverted, and the full menu suite passes in both jsdom (805 tests) and Chromium (286 tests).

What it does

Previously, while allowMouseEnter was still false (menu opened via keyboard/programmatically, no mouse movement yet), the submenu trigger collapsed its hover delay to 0, which pushed the open onto the rest-only path (restMs) — so the submenu only opened once the cursor stopped moving. The PR always passes the plain delay and instead gates the open through the hover hook's shouldOpen callback, which re-reads allowMouseEnter lazily when the delay timer actually fires.

Correctness

  • The core mechanism is right: for delay > 0, shouldOpen is evaluated at timer-fire time, by which point any genuine hover has produced a mousemove that set allowMouseEnter. A phantom mouseenter (menu rendered under a stationary cursor) is still vetoed, and even a veto is recoverable via the restMs fallback path.
  • The delay > 0 ? ... : undefined conditional is necessary, not defensive: at delay = 0 the open is synchronous with no later re-check and restMs is also 0, so an unconditional gate could permanently suppress the submenu (the native trigger listener runs before React's delegated onMouseMove sets the flag). The delay = 0 behavior is unchanged from master — including its pre-existing lack of phantom-enter protection.
  • Subtle behavior change worth being aware of (looks intentional and more correct): closeDelay previously also collapsed to 0 while allowMouseEnter was false; now it always applies. Hard to hit in practice since a submenu is rarely open in that phase.
  • shouldOpen now also gates the immediate-open path (moving between sibling triggers while a submenu is open). I couldn't construct a scenario where allowMouseEnter is false there with real mouse input, and a veto would be the conservative outcome anyway.

Code quality

  • Nice side benefit: dropping the parentMenuStore.useState('allowMouseEnter') subscription means submenu triggers no longer re-render when the flag flips — the lazy select read in the callback is strictly leaner.
  • Consistent with the existing shouldOpen precedent in TooltipTrigger; no changes to the shared hook were needed.

Test coverage

  • The test discriminates correctly, which I confirmed by mutation: it fails on master's source in both contained- and detached-triggers modes. The design details matter and are right — movementX: 10 defeats jsdom's default movement = 0 (which would be treated as resting), and the 3×40ms ticks stop at 120ms, before the rest timer (last reset at 80ms → fires at 180ms) could open it, so only the plain-delay path can make it pass.
  • Conventions match the neighboring fake-timer blocks (createRenderer per describe, clock.withFakeTimers(), not.toBe(null) assertions).
  • One optional nit: the sibling fake-timer test ("reopens on hover after an impatient click closes via item press") fires fireEvent.pointerEnter(trigger, { pointerType: 'mouse' }) before the mouse events; the new test omits it and relies on undefined passing the non-strict isMouseLikePointerType check. Works fine, but adding it would make the mouseOnly: true interaction explicit and resilient if that check ever becomes strict. Not blocking.

No security or performance concerns — if anything, performance improves slightly via the removed re-render subscription.

@atomiks
atomiks merged commit 19272a3 into mui:master Jun 9, 2026
6 checks passed
@atomiks
atomiks deleted the codex/menu-submenu-hover-plain-delay branch June 9, 2026 22:53
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