Skip to content

feat(NumberInput): add family-aligned isLoading and changeAction support - #5978

Open
Alif416 wants to merge 2 commits into
meta:mainfrom
Alif416:feat/numberinput-family-alignment
Open

Alif416 wants to merge 2 commits into
meta:mainfrom
Alif416:feat/numberinput-family-alignment

Conversation

@Alif416

@Alif416 Alif416 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

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

  • isLoading prop: Indicates when field value is resolving or being saved (does not conflate with option-source loading)
  • changeAction callback: Async action that runs after onChange in a React transition, enabling optimistic updates
  • Optimistic state management: Uses useOptimistic hook for immediate visual feedback while async work completes
  • Consistent value-change paths: Apply changeAction to text commit, step increment/decrement, and clear button actions

Implementation Details

Per the input-field family specification (FR5, FR6):

  • onChange fires immediately when user action occurs
  • Optimistic value updates show proposed change instantly
  • changeAction runs in a React transition for async operations
  • Both synchronous and asynchronous flows preserve immediate user feedback
  • Maintains existing behavior for components not using changeAction

Testing

  • Component accepts and uses isLoading prop
  • changeAction invoked on value change (text, step, clear)
  • Optimistic values update before async work completes
  • Unchanged legacy path without changeAction still works
  • Prop documentation added to NumberInput.doc.mjs

Fixes #5941

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
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 3, 2026
@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Sep 3, 2026
github-actions Bot added a commit that referenced this pull request Sep 3, 2026
@github-actions

github-actions Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Current run: The current CI run concluded failure. Current analysis and preview links are unavailable.


Generated by PR Enrichment workflow | View current CI run

@cixzhang cixzhang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

vercel Bot commented Sep 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 4, 2026 4:17am UTC

Request Review

@Alif416 Alif416 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

github-actions Bot added a commit that referenced this pull request Sep 4, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 NaN value shows a permanent loading state. The busy check compares the optimistic and controlled values with !==, and NaN !== NaN is always true, so a field with value={NaN} renders the spinner and aria-busy forever even when nothing is loading or pending. A NaN-safe comparison (for example Object.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 that onChange runs before changeAction. 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's onChange is 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]

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 changeAction so <NumberInput {...props} hasClear /> still compiles; it now fails with TS2322, which turns the Storybook typecheck red.
  • Compare with Object.is so value={NaN} no longer shows a permanent spinner and aria-busy, and add a regression test.
  • Add tests for typed commits (blur and Enter) and typed clear that record onChange running before changeAction.
  • Rebase onto main, keeping changeAction in 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>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +1031 to +1033
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +18 to +20
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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

cixzhang pushed a commit that referenced this pull request Oct 24, 2026
…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 |

![Clear tap before and after: TextInput, then NumberInput](https://raw.githubusercontent.com/vjeux/astryx/evidence/c08-clear-keyboard/clear-keyboard/clear-tap-keyboard.png)

- 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.
@cixzhang
cixzhang dismissed their stale review November 18, 2026 21:23

(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.

This branch was successfully deployed

1 active deployment
Preview — 2c79ab0e Deployed Sep 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Close recorded input-family public prop gaps

2 participants