Skip to content

[number field] Preserve consumer selection when focusing the input - #5619

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:claude/number-field-selection-bug-96153a
Sep 2, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:claude/number-field-selection-bug-96153a

Conversation

@atomiks

@atomiks atomiks commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #5578. focusInput() (steppers, scrub area, hidden-input focus redirect) called focus() and then setSelectionRange(end). A consumer onFocus runs synchronously inside focus(), so anything it did with the selection (for example event.currentTarget.select()) was overwritten right after.

Changes

  • Store the end caret with setSelectionRange before calling focus() and drop the post-focus write. Chromium, Firefox and WebKit all restore a stored selection on programmatic focus, none of them focus the input from setSelectionRange, and a selection set inside a focus listener sticks in all three. WebKit only selects the whole value when nothing was ever stored, which is what the post-focus write was working around.
  • Regression tests on the hidden-input redirect and a scrub-area mouse press. The stepper buttons are not a useful test here: pressing one changes the value on pointerdown, and React's input.value assignment moves the caret to the end in every engine regardless of this code.

@atomiks atomiks added component: number field Changes related to the number field component. type: bug It doesn't behave as expected. internal Behind-the-scenes enhancement. Formerly called “core”. and removed type: bug It doesn't behave as expected. labels Sep 2, 2026
@pkg-pr-new

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

commit: d1610bd

@atomiks
atomiks marked this pull request as ready for review September 2, 2026 12:59
@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 0B(0.00%) ▼-1B(0.00%)

Details of bundle changes

Performance

Total duration: 875.23 ms -88.67 ms(-9.2%) | Renders: 76 (+0) | Paint: 1,393.68 ms -165.97 ms(-10.6%)

Test Duration Renders
Select open (500 options) 36.05 ms ▼-12.22 ms(-25.3%) 14 (+0)
Combobox type — 500 items, all stay mounted (type "Row ") 23.94 ms ▼-10.67 ms(-30.8%) 11 (+0)

13 tests within noise — details


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

@netlify

netlify Bot commented Sep 2, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit d1610bd
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a981d370b2ee60008f80132
😎 Deploy Preview https://deploy-preview-5619--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 merged commit b7f6683 into mui:master Sep 2, 2026
26 of 27 checks passed
@atomiks
atomiks deleted the claude/number-field-selection-bug-96153a branch September 2, 2026 13:52
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. internal Behind-the-scenes enhancement. Formerly called “core”.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants