Repository navigation
Conversation
Implement input-family aligned async action support for NumberInput: - Add isLoading prop to indicate when field value is resolving or being saved - Add changeAction callback for async operations that run in React transitions - Support optimistic value updates while async work completes - Maintain immediate onChange feedback before changeAction runs - Apply changeAction to all value-change paths: text commit, stepping, and clear Aligns NumberInput with input-family contract (FR5, FR6) alongside existing members like TextInput. Both synchronous onChange and async changeAction follow the documented pattern: onChange fires first, proposed value shows optimistically, changeAction runs in a transition. Per input-field family specification: - isLoading indicates field value is resolving (not option-source loading) - changeAction runs after onChange without conflating input busy with source busy - Preserves existing no-new-prop behavior for components not yet adopting
PR Analysis Report
Generated by PR Enrichment workflow | View current CI run |
cixzhang
left a comment
There was a problem hiding this comment.
Thanks for taking this family gap. In Chromium, a pending increment stays at 1 with no spinner or aria-busy; a second increment submits 2 again. Please render from the optimistic value across text, step, and clear paths, expose one busy presentation, and add focused tests. The clear paths also fail the package build because the new callback excludes null. Please mirror the public docs too.
[Reviewed by Robohands]
The optimistic value was set but never read, so every display and derivation still came off the controlled `value` prop: the field showed the stale number during an in-flight changeAction, and stepping recomputed from that stale base and resubmitted the same value. Render from the optimistic value across the text, step, and clear paths, including aria-valuenow and clear-button visibility. Wire the previously unused isBusy to a single presentation: aria-busy plus one Spinner in the end lane, matching TextInput. Fix the package build by moving changeAction into the hasClear discriminated union so it widens to `number | null` alongside onChange when the field is clearable, and route all three value-change paths through one helper. Mirror the prop contract in docs, docsZh and docsDense, and add a changeset.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Alif416
left a comment
There was a problem hiding this comment.
Good catch, all of it was real. The optimistic value was getting set but nothing was reading it, so the field, aria-valuenow, the clear button and the stepping base were all still coming off the value prop. That's both the stale 1 and the second increment resubmitting 2.
isBusy was dead code as well. It now sets aria-busy on the input and renders a single Spinner in the end lane, in the same spot TextInput puts it.
The build break is fixed by moving changeAction into the hasClear union so it widens to number | null the same way onChange already does. I also pulled the three value change paths into one helper instead of three copies of the same transition block.
Added six tests. To check they actually catch the bug I reverted the component and kept the tests, and five of them fail with the symptoms you described. The sixth covers the path with no changeAction, so it passes either way on purpose. Docs are mirrored in docsZh and docsDense now, and there's a changeset.
One thing worth flagging: I left the hidden form input submitting the committed value rather than the optimistic one, since a form probably shouldn't send a value that a pending changeAction might still reject. Happy to change it if you'd rather it follow the optimistic value.
There was a problem hiding this comment.
Thanks for closing this family gap — the direction looks right: isLoading and changeAction follow the input-field family contract, the optimistic value now drives the field, aria-valuenow, clear, and stepping, and the legacy path without the new props is unchanged. I verified the new stepper/clear/loading tests pass and the package builds.
Two small things before this can be approved:
- A
NaNvalue shows a permanent loading state. The busy check compares the optimistic and controlled values with!==, andNaN !== NaNis always true, so a field withvalue={NaN}renders the spinner andaria-busyforever even when nothing is loading or pending. ANaN-safe comparison (for exampleObject.is-style equality) plus a regression test for that value at rest would fix it. - The typed-entry path and callback order are not yet tested. The family contract requires focused evidence for every value-change path that can run
changeAction, including thatonChangeruns beforechangeAction. The new tests cover stepper clicks, clear, and explicit loading, but not typing a value and committing with blur or Enter — and the test owner'sonChangeis a no-op, so order is never actually asserted. One focused typed-commit test recording the call order would close this.
Neither needs a redesign; once those land this should be ready.
[Automated review]
There was a problem hiding this comment.
Thanks for the follow-up: the field, aria-valuenow, stepping and clear now follow the optimistic value, and one spinner sits in the end lane without overlapping anything. Approval needs a maintainer to provide or identify the governing spec for which value a native form submits under htmlName while a changeAction is pending (today the committed value with formatValue, the proposed value without it); once that is settled, both form paths and the changeset should match it. Independently of that decision, please:
- Type
changeActionso<NumberInput {...props} hasClear />still compiles; it now fails with TS2322, which turns the Storybook typecheck red. - Compare with
Object.issovalue={NaN}no longer shows a permanent spinner andaria-busy, and add a regression test. - Add tests for typed commits (blur and Enter) and typed clear that record
onChangerunning beforechangeAction. - Rebase onto
main, keepingchangeActionin its updated clear handler.
[Automated review]
| * value is shown optimistically while it runs, and it contributes to the | ||
| * same busy presentation as `isLoading`. | ||
| */ | ||
| changeAction?: (value: number) => void | Promise<void>; |
There was a problem hiding this comment.
Splitting changeAction across the hasClear union makes <NumberInput {...props} value={value} onChange={setValue} hasClear /> fail with TS2322: the spread carries this (value: number) type into the clearable branch. CI's Storybook typecheck fails on NumberInput.stories.tsx:682 and :693 for exactly this reason. One shared changeAction?: (value: number | null) => void | Promise<void> on the base props type-checks both the spread and the new tests.
| // One busy presentation for the whole family concept: an explicit isLoading | ||
| // and an in-flight changeAction are the same state to the user, so they | ||
| // resolve to a single flag driving a single indicator (never two). | ||
| const isBusy = isLoading || optimisticValue !== value; |
There was a problem hiding this comment.
NaN !== NaN, so a field with value={NaN} renders the Spinner and aria-busy forever with nothing pending. !Object.is(optimisticValue, value) plus a regression test fixes it.
| Deliberately the committed `value`, not the optimistic one: a form must | ||
| submit what the owner has actually accepted, never a proposed value | ||
| that a pending changeAction may still reject. |
There was a problem hiding this comment.
This holds only when formatValue is set. Without it the visible input keeps name and submits the proposed value while an Action is pending. Once a maintainer settles which value forms should send, both paths need to match it.
| to `(value: number | null)` when the field is clearable. Form submission continues | ||
| to send the committed `value`, not a proposed one. Callsites that pass neither | ||
| prop are unaffected. |
There was a problem hiding this comment.
Two of these claims don't hold yet: without formatValue, form submission sends the proposed value during a pending Action, and callsites that spread NumberInputProps and set hasClear stop compiling even when they pass neither new prop.
…S keyboard (#8183) ## User impact On an iPhone, tapping the clear button of a TextInput or NumberInput that is not focused empties the field and focuses it, but no keyboard comes up. The person has to tap the field again to type the replacement they cleared the field for. ## Problem and solution fit Since #5440, the clear button's pointer path focuses the field a frame later (`requestAnimationFrame`). iOS Safari raises its keyboard only for a focus made while handling the touch, so the later focus lands with no keyboard. #5440 deferred the focus to avoid a page jump to the top. `preventScroll`, which that change also added, is what prevents the jump; the deferral only broke the keyboard. This change keeps `preventScroll` and focuses inside the tap. ## Expected behavior and authority UIKit's clear button makes its field the first responder: in a UIKit app on iOS 26.2 the keyboard starts rising 75 ms after the lift. No current record says otherwise; #5440 is the regression history. Siblings: #8158 makes the same change in PanelSearchInput; #6425, #7690, #7910, #7940 (TextInput) and #5978, #8015 (NumberInput) touch the same files with other intents. ## Smallest restoration Two lines in each of TextInput and NumberInput: the pointer path calls `focus({preventScroll: true})` directly instead of in the next frame. The keyboard and assistive-technology path (`detail === 0`) is unchanged, as is the clear button's `preventDefault` on pointerdown, which keeps a focused field focused. DateInput, TimeInput, DateTimeInput and FileInput have the same pattern; their lanes own them. ## Evidence Mobile Safari, iOS 26.2 (simulator), page scrolled 254 px, field unfocused with a value, one tap on its clear button: | | keyboard | page scroll | | --- | --- | --- | | TextInput before | none (viewport stays 714) | stays 254 | | TextInput after | up (viewport 714 → 377) | stays 254 | | NumberInput before | none | stays 254 | | NumberInput after | number pad (714 → 404) | 254 → 266: Safari reveals the field the pad would cover |  - Regression tests: the pointer path focuses synchronously, with `preventScroll`, and without `requestAnimationFrame`. This replaces the test that pinned the deferral. ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing - `pnpm vitest run` on TextInput, NumberInput and Field: 15 files, 600 tests. - Core typecheck, eslint and prettier on touched files, `check:changesets`. - Mobile Safari on the iOS 26.2 simulator (iPhone 17 Pro): the four runs above, with visual viewport, focus and scroll events read from the page.
(Posted by Cindy's agent.) Dismissed as stale on the owner's decision: this review is on an outdated head. Please re-review the current head if concerns remain.
Summary
Add input-family aligned async action support to NumberInput component, enabling optimistic value updates and async operations to align with the input-field family contract.
Changes
Implementation Details
Per the input-field family specification (FR5, FR6):
onChangefires immediately when user action occurschangeActionruns in a React transition for async operationsTesting
Fixes #5941