Skip to content

[number field] Fix input and scrub edge cases - #5046

Merged
atomiks merged 14 commits into
mui:masterfrom
atomiks:number-field/fixes
Jun 15, 2026
Merged

atomiks merged 14 commits into
mui:masterfrom
atomiks:number-field/fixes

Conversation

@atomiks

@atomiks atomiks commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Fixes several Number Field interaction, validation, and commit edge cases.

Changes

  • Fixed read-only focus state, paste handling, hidden input validation, and wheel scrubbing guards.
  • Fixed seeded increment behavior for empty negative ranges with snapOnStep.
  • Fixed redundant or missing onValueCommitted calls for wheel, blur, keyboard, and canceled changes.
  • Fixed caret-aware paste insertion and allowed native handling for unhandled multi-character keys.
  • Fixed scrub area cleanup when it unmounts mid-scrub.
  • Restored pre-round clamping for fractional bounds.
  • Removed invalid aria-readonly from stepper buttons; read-only steppers are now exposed as unavailable through button disabled semantics (supersedes [number field]: Fix readonly stepper semantics #5047).
  • Added targeted regression tests.

@atomiks atomiks added the component: number field Changes related to the number field component. label Jun 15, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 15, 2026
@code-infra-dashboard

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

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+469B(+0.10%) 🔺+175B(+0.12%)

Details of bundle changes

Performance

Total duration: 1,208.68 ms -2.52 ms(-0.2%) | Renders: 50 (+0)

No significant changes — details


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

@netlify

netlify Bot commented Jun 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit a911c29
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a3000f551bea600089e0084
😎 Deploy Preview https://deploy-preview-5046--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 changed the title [number-field] Bug fixes [number field] Fix input and scrub edge cases Jun 15, 2026
@atomiks atomiks added the type: bug It doesn't behave as expected. label Jun 15, 2026 — with ChatGPT Codex Connector
atomiks added 8 commits June 15, 2026 17:47
- Keep the global pointerup release listener registered through stopAutoChange
  (deduped per hold) so a hold that auto-stops at a boundary still commits on
  release, while a mouseleave/mouseenter cycle no longer double-commits.
- Don't commit when blurring an untouched empty field, and respect a canceled
  clear on blur.
- Don't commit on keyboard steps that don't change the value, and treat a
  canceled change as not applied (setValue returns false when canceled).
…ange

- Let the browser handle multi-character keys the field doesn't act on (PageUp,
  Insert, F-keys, Home/End without a min/max) instead of calling stopEvent.
- Allow the minus key via keyboard when allowOutOfRange is set so native
  underflow validation is reachable even when min >= 0.
Splice the clipboard text into the value at the caret/selection (instead of
replacing the whole value) and restore the caret just after the inserted text.
If the scrub area unmounts while a scrub is active, exit pointer lock so the
document isn't left pointer-locked until the user presses Escape.
- Reset blockRevalidationRef on blur when validation normalizes the value back
  to the current value, so the next external change still revalidates.
- Validate the stored (clamped) value on hidden-input autofill and drop the
  redundant setDirty.
Each wheel turn is a discrete, final change, so commit it immediately with
reason 'wheel' (gated on an actual change) instead of only committing later on
blur. Adds wheel edge-case coverage (ctrlKey, unfocused, shift largeStep).
…ge seed

- Keep focus/touched state in sync for read-only inputs (they're still focusable).
- Mark the hidden form input readOnly so a read-only required field doesn't block
  native form validation.
- Seed an empty field's first step with the in-range value nearest 0 (clamped),
  avoiding an out-of-range seed for fully-negative ranges.
- Add coverage for wheel under disabled/readOnly, invalid/readOnly paste, stepper
  ARIA, and the negative-range seed.
…tate

- Seed an empty field's first step without a direction so `snapOnStep` doesn't
  directionally snap the seeded value off its in-range position (e.g. a fully
  negative range would otherwise land below `max`).
- Clear the root's scrubbing state when the scrub area unmounts mid-scrub, so
  `data-scrubbing` doesn't stay stuck on the still-mounted root/input.
- Add coverage for both.
@atomiks
atomiks force-pushed the number-field/fixes branch from 2d82dd5 to 934da4f Compare June 15, 2026 07:52
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 15, 2026
@pkg-pr-new

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

commit: a911c29

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 15, 2026
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 15, 2026
@atomiks
atomiks marked this pull request as ready for review June 15, 2026 08:57

@flaviendelangle flaviendelangle 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.

PR Review Summary — #5046 [number field] Fix input and scrub edge cases

Verdict: Approve. This is a high-quality, well-tested bug-fix PR. The code-reviewer agent ran the full suite in the PR worktree: 354 tests pass (16 skipped), pnpm typescript clean, pnpm eslint clean on all four changed source files. No correctness bugs, silent failures, or guideline violations were found across all four review dimensions. The findings below are all minor/advisory.

Critical Issues (0)

None.

Important Issues (0)

None blocking. The closest items are coverage and maintainability notes below.

Suggestions

Test coverage gaps (pr-test-analyzer):

  • NumberFieldInput.tsx:226-230 — The blockRevalidationRef reset (if (committedValue === value)) fixes a real stale-validation regression but has no end-to-end test for the two-step sequence: a blur that normalizes text back to the current stored value, followed by an external value change that must re-validate. Existing tests cover each half but not the combination. Worth a targeted validationMode="onBlur" test.
  • usePressAndHold.ts:166-172 — The unmount cleanup of the global pointerup listener is untested. The mouseleave/mouseenter double-commit fix is well covered; only unmounting the stepper mid-hold is not. Low priority (scrub-area got an analogous unmount test).

Comment precision (comment-analyzer):

  • NumberFieldInput.tsx:180-182 — The empty-field-blur commit comment names only two of the three OR clauses; it omits the value !== null case ("an actual clear"). A reader could mistakenly simplify the guard. Add a clause covering it.
  • NumberFieldInput.tsx:95-103 — The pendingCaretRef useIsoLayoutEffect runs on every render (no deps) intentionally. A one-line note would stop a future reader from "fixing" it with a dependency array and breaking caret timing.

Maintainability (silent-failure-hunter):

  • NumberFieldRoot.tsx:246 — On cancel, setValue returns false before lastChangedValueRef is updated (correct). A brief comment that the ref is deliberately left untouched on cancel — so the per-interaction reset guards remain authoritative — would prevent a future edit from reintroducing staleness.

Strengths

  • Correctness of the core mechanism verified end-to-end: the setValue→changed return-value plumbing is consistent across all four incrementValue call sites; boundary no-ops and canceled changes correctly avoid committing, and lastChangedValueRef.current ?? valueRef.current always resolves to the freshly-set value because the ref is updated synchronously inside setValue.
  • Excellent test coverage of the behavioral fixes: onValueCommitted dedup across wheel/blur/keyboard/canceled paths, negative-range seeding (-5 not -6, no directional snap), wheel guards (disabled/readOnly/ctrlKey/unfocused/largeStep), paste-at-caret variants, Home/End without min/max, non-printing key passthrough, and the scrub-area unmount cleanup (correctly Chromium-gated).
  • The exitPointerLock try/catch suppression (NumberFieldScrubArea.tsx:266-274) is justified — it mirrors the pre-existing pattern at lines 161-164, the call genuinely can throw on a detached node, local state is reset before the call, and it's internal teardown (not a public error).
  • Comments are unusually high-value — they explain why, not what, and every one was verified accurate against the implementation.
  • Full guideline compliance: useIsoLayoutEffect, useTimeout/useInterval, useStableCallback, ownerDocument, and the NOOP/clamp utils all used per AGENTS.md.

Recommended Action

Mergeable as-is. Optionally, before merge: add the blockRevalidationRef regression test (the one untested behavioral fix), and tighten the two comment notes at NumberFieldInput.tsx:180-182 and :95-103. Everything else is nice-to-have.

@atomiks
atomiks merged commit 6821719 into mui:master Jun 15, 2026
6 checks passed
@atomiks
atomiks deleted the number-field/fixes branch June 15, 2026 13:48
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.

2 participants