Skip to content

[number field] Fire ScrubArea onClick once per click - #5889

Merged
michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/fix-number-field-scrub-double-click
Oct 6, 2026
Merged

michaldudak merged 1 commit into
mui:masterfrom
michaldudak:claude/fix-number-field-scrub-double-click

Conversation

@michaldudak

Copy link
Copy Markdown
Member

Clicking NumberField.ScrubArea without dragging can call its onClick twice.

On pointerup with no movement, the scrub area dispatches a synthetic click, because its comment assumes that preventDefault() on pointerdown suppresses the browser's click. It doesn't: preventDefault() on pointerdown only suppresses the compatibility mouse events, not click.

  • With pointer lock granted, the browser's click targets the lock element (<body>), so the synthetic click is the only one the scrub area sees. That case works today.
  • Without pointer lock, the native click also reaches the scrub area, so onClick fires twice. That happens in WebKit, which never requests the lock, and whenever the lock request is denied (e.g. in an iframe without allow-pointer-lock).

With real browser input in Chromium (pointer lock not granted in the test runner), one click produced two onClick calls.

The fix records whether a native click reached the scrub area (onClickCapture), and defers the synthetic click by one task. The browser dispatches its click in the same task as pointerup. The synthetic click is skipped when the native one already arrived. Firefox already defers the handler by 20 ms, so the same check applies there.

Why the existing test didn't catch it

"should fire onClick when clicked without scrubbing" rendered no NumberField.Input, so the scrub listener, and with it the click synthesis, never ran. The single onClick came from user-event's own click. The test now renders an input and uses real browser input (vitest/browser's userEvent).

Validation

  • The updated test fails without the source change ("expected 1 times, but got 2 times") and passes with it.
  • NumberFieldScrubArea suites pass in jsdom and twice in Chromium. ESLint and Prettier pass.
  • Not verified manually in Safari or with pointer lock granted. With the lock, the native click goes to <body>, so the synthetic click still fires once.

Found during an audit of the test suite for tests that can't fail.

The scrub area synthesizes a click on pointerup when the pointer didn't move,
assuming that preventDefault on pointerdown suppresses the browser's click.
It doesn't. With pointer lock the native click targets the lock element, but
without it (WebKit never requests the lock, and requests can be denied) the
native click reaches the scrub area too, so onClick fired twice.

Defer the synthesized click by one task and skip it when a native click
already reached the scrub area.
@michaldudak michaldudak added component: number field Changes related to the number field component. type: bug It doesn't behave as expected. labels Oct 5, 2026
@pkg-pr-new

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

commit: 5fbea53

@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+116B(+0.02%) 🔺+35B(+0.02%)

Details of bundle changes

Performance

Total duration: 433.22 ms -16.25 ms(-3.6%) | Renders: 76 (+0) | Paint: 795.39 ms -26.05 ms(-3.2%)

No significant changes — details


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

@netlify

netlify Bot commented Oct 5, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 5fbea53
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6ac3a6392fe88500086a986c
😎 Deploy Preview https://deploy-preview-5889--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 marked this pull request as ready for review October 5, 2026 13:44
@michaldudak
michaldudak merged commit 7d93b48 into mui:master Oct 6, 2026
27 checks passed
@michaldudak
michaldudak deleted the claude/fix-number-field-scrub-double-click branch October 6, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant