Repository navigation
[number field] Fix input and scrub edge cases - #5046
Conversation
Bundle size
PerformanceTotal 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. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
- 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.
2d82dd5 to
934da4f
Compare
commit: |
flaviendelangle
left a comment
There was a problem hiding this comment.
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— TheblockRevalidationRefreset (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 targetedvalidationMode="onBlur"test.usePressAndHold.ts:166-172— The unmount cleanup of the globalpointeruplistener 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 thevalue !== nullcase ("an actual clear"). A reader could mistakenly simplify the guard. Add a clause covering it.NumberFieldInput.tsx:95-103— ThependingCaretRefuseIsoLayoutEffectruns 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,setValuereturnsfalsebeforelastChangedValueRefis 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→changedreturn-value plumbing is consistent across all fourincrementValuecall sites; boundary no-ops and canceled changes correctly avoid committing, andlastChangedValueRef.current ?? valueRef.currentalways resolves to the freshly-set value because the ref is updated synchronously insidesetValue. - Excellent test coverage of the behavioral fixes: onValueCommitted dedup across wheel/blur/keyboard/canceled paths, negative-range seeding (
-5not-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
exitPointerLocktry/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 theNOOP/clamputils 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.
Fixes several Number Field interaction, validation, and commit edge cases.
Changes
snapOnStep.onValueCommittedcalls for wheel, blur, keyboard, and canceled changes.aria-readonlyfrom stepper buttons; read-only steppers are now exposed as unavailable through button disabled semantics (supersedes [number field]: Fix readonly stepper semantics #5047).