Skip to content

[menu] Forward native event on item press close - #5789

Merged
michaldudak merged 5 commits into
mui:masterfrom
michaldudak:claude/wizardly-mcclintock-b82d33
Sep 28, 2026
Merged

michaldudak merged 5 commits into
mui:masterfrom
michaldudak:claude/wizardly-mcclintock-b82d33

Conversation

@michaldudak

@michaldudak michaldudak commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Problem

When a Menu item press closed the menu, the item's onClick emitted the React synthetic event as the close event. FloatingFocusManager classifies the close interaction with instanceof MouseEvent, which a synthetic event never passes. As a result, finalFocus callbacks always received '' instead of 'keyboard' or 'mouse', and keyboard selection never restored focus-visible on the trigger.

Solution

Emit event.nativeEvent instead. The keyboard-click check in MenuRoot (detail === 0) reads the same value from the native event, so it behaves as before.

The drag-release selection (press the trigger, drag onto an item, release) dispatches a synthesized PointerEvent click with an empty pointerType, which would now be classified as 'keyboard'. dispatchClickWithModifiers accepts a pointerType option, and the drag-release path passes 'mouse'.

Added MenuPopup tests asserting finalFocus receives 'mouse' after a pointer click and after a drag-release selection, and 'keyboard' after selecting an item with Enter.

@michaldudak michaldudak added component: menu Changes related to the menu component. type: bug It doesn't behave as expected. labels Sep 24, 2026
@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@5789
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5789
    

commit: 4b15f8e

@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 🔺+81B(+0.02%) 🔺+22B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,136.10 ms -19.82 ms(-1.7%) | Renders: 76 (+0) | Paint: 1,835.85 ms -58.32 ms(-3.1%)

Test Duration Renders
Popover mount (300 instances) 49.24 ms 🔺+9.65 ms(+24.4%) 1 (+0)
Dialog mount (300 instances) 31.33 ms 🔺+6.96 ms(+28.5%) 1 (+0)
Combobox type — 500 items, narrows to ~11 (type "Row 25") 28.20 ms ▼-7.96 ms(-22.0%) 15 (+0)

12 tests within noise — details

Metric alarms

Test Metric Change
Popover mount (300 instances) bench:paint 🔺 +17.68 ms

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 4b15f8e
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ab62f9fde6a3c00082d5a07
😎 Deploy Preview https://deploy-preview-5789--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 Sep 25, 2026

Copy link
Copy Markdown
Contributor

PR review

Nothing blocks merge. There is one narrow regression: a touch item press now hits MenuRoot's delayed-tap guard. I reproduced it with real touch taps in Chromium (CDP) and checked that master closes the menu in the same flow.

Bugs (1)

1. 🟠 Touch item press can leave the menu open after a focus-open

Location: packages/react/src/menu/root/MenuRoot.tsx:351

nextOpen === false &&
nativeEvent?.type === 'click' &&
(nativeEvent as PointerEvent).pointerType === 'touch' &&
!allowTouchToCloseRef.current

The native click now has pointerType: 'touch', so an itemPress close is ignored for 300 ms after a trigger-focus open. The synthetic event used before had no pointerType.

Failure scenario: In a Menubar with a menu open, press ArrowRight to open the next menu (keyboard + touchscreen), then tap an item within ~280 ms. The item's onClick runs but the menu stays open. On master it closes.

Fix: Add reason !== REASONS.itemPress && to the guard. With that change, the menu closes at every gap in the probe, and the menu, menubar, and context-menu Chromium suites pass. A test for this would help: Menubar + ArrowRight + touch click on an item within 300 ms.

Verdict

Approve after nits - the only finding is a narrow mixed-input regression with a one-line fix.


🤖 Review generated with Claude Code

@michaldudak
michaldudak merged commit 62b54e8 into mui:master Sep 28, 2026
24 checks passed
@michaldudak
michaldudak deleted the claude/wizardly-mcclintock-b82d33 branch September 28, 2026 08:08
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