Repository navigation
fix(TextInput): dispatch changeAction and update optimistic value on clear - #6425
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| richtext/RichTextEditorToolbar | 278.2 kB (+122 B) · 454 B CSS (0) | — | — · — · — |
| lab/CommentThread | 344.0 kB (+118 B) · 2.4 kB CSS (0) | — | — · — · — |
| lab/Comments | 350.9 kB (+113 B) · 2.5 kB CSS (0) | — | — · — · — |
11 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| lab/EmojiPicker | 87.0 kB (+98 B) · 751 B CSS (0) | — | — · — · — |
| lab/CommentComposer | 151.7 kB (+91 B) · 1.9 kB CSS (0) | — | — · — · — |
| lab/TransferList | 101.7 kB (+91 B) · 1.2 kB CSS (0) | — | — · — · — |
| lab/TransferListSelector | 109.2 kB (+85 B) · 1.4 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 106.0 kB (+83 B) · 773 B CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 107.2 kB (+82 B) · 1.1 kB CSS (0) | — | — · — · — |
| TextInput · Storybook | 67.9 kB (+80 B) · 11.2 kB CSS (0) | 417 (+1) | ✓ · ✓ · — |
| PowerSearch | 287.0 kB (+50 B) · 24.1 kB CSS (0) | — | — · — · — |
| BaseTypeahead | 71.2 kB (0) · 10.9 kB CSS (0) | — | ✓ · ✓ · ✓ |
| TypeaheadItem | 6.4 kB (0) · 3.6 kB CSS (0) | — | ✓ · ✓ · ✓ |
| Typeahead | 79.7 kB (−6 B) · 12.4 kB CSS (0) | — | ✓ · ✓ · ✓ |
Package size: @astryxdesign/core 7.20 MB packed (+605 B); no new dependencies.
API changes: none in this pull request
Committed API report behind this build: cli 29 rows, core 34 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.
Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.
Generated by PR Enrichment workflow | View full report
…clear TextInput provides a clear button when hasClear is enabled. Previously handleClear only invoked onChange with an empty string, bypassing changeAction entirely and failing to update optimisticValue. Under the input fields family specification FR6, clearing an input must initiate pending transitions through changeAction and present optimistic feedback until settled. This update invokes changeAction inside startTransition alongside setOptimisticValue and adds unit test coverage for the pending state. Signed-off-by: Manohar Paturi <[email protected]>
88ff5af to
6358f27
Compare
There was a problem hiding this comment.
Thanks for closing the TextInput clear gap: running changeAction with the optimistic empty value and busy state is the right behavior, but this needs changes before it can merge. The clear path calls changeAction('', null), while TextInput's changeAction type and docs promise a ChangeEvent<HTMLInputElement>, so an Action that reads e.target (for example e.target.name) throws when someone presses × and its error boundary replaces the field. Please give the clear path a real change event (for example by routing it through the input's own change handler, as Typeahead.tsx already does with a native value setter and an input event, which also keeps onChange first and the documented preventDefault cancellation), update the clear test to check that event and that onChange runs before changeAction, and rebase onto main, where TextInput.test.tsx now conflicts at its last lines.
[Automated review]
…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.
|
Taking this next: routing the clear path through a native change event (value setter plus input event, as Typeahead does), updating the clear test to assert the event shape and the onChange-before-changeAction order, and rebasing onto current main where TextInput.test.tsx conflicts. |
# Conflicts: # packages/core/src/TextInput/TextInput.test.tsx
There was a problem hiding this comment.
Thanks for carrying this forward: routing × through the input's own change handler gives onChange and changeAction a real change event, keeps onChange first with its preventDefault() cancellation, and shows the optimistic empty value and busy state, as the TextInput contract asks. One change is needed before this can merge:
TextInput.tsx:462-470adds a third copy of the native value-set andinput-event code thatTypeahead.tsxalready has twice (:516-523and:589-597); please move it into one shared helper underpackages/core/src/utils/and call it from TextInput'shandleClearand both Typeahead sites, so a later fix to it reaches every caller.
Two optional notes: the comment above handleClear restates the function name and packs four topics into one long sentence (a shorter wording is in the inline comment), and the TextInput and input-fields records still list the clear gap this fixes, which a maintainer can remove.
[Automated review]
…Typeahead's edit and clear The native value set plus an input event had three copies. They now call one internal helper in utils, not exported from the package, with no behavior change. The TextInput record and the input-fields family drop the clear-skips-the-Action gap this PR closes.
|
/approve-spec 695d364 |
There was a problem hiding this comment.
Approved pending CI: CI has not finished on this head yet.
The clear button now goes through the input's own change handler, so onChange and changeAction receive a real change event, preventDefault() in onChange cancels the Action, and the field shows the optimistic empty value and busy state while the Action runs, as the TextInput contract asks. The shared setInputValue helper also settles the earlier duplication finding, and the tests show the clear path failing on the old code and passing here. Optional: since this edits two knowledge records, add a ## Writing rubric results section to the description (each item would read "none").
[Automated review]
When TextInput renders a clear affordance via hasClear, clicking clear previously triggered onChange('', null) but completely bypassed changeAction. In addition, optimisticValue was not updated to reflect the cleared value while any transition was in flight.
Under the input fields family contract documented in docs/families/input-fields.md (FR6), all user-driven mutations must dispatch through changeAction and maintain optimistic values during pending transitions.
This change invokes changeAction with an empty string within startTransition alongside setOptimisticValue, and adds unit test coverage verifying that changeAction receives the clear event and holds optimistic empty state while pending.
Maintainer carry (@cixzhang)
Carried forward on this branch with @ManoharPaturi's commit kept, after the review findings:
inputevent, asTypeaheadalready does), soonChangeandchangeActionget a realChangeEventwhosetargetis the input. An Action that readse.targetno longer throws on clear.onChangeruns first, and itspreventDefault()cancels the Action, as it does for typing.onChangeruns beforechangeAction. A new case checks thatpreventDefault()inonChangestops the Action. The optimistic empty value and busy state case is kept.TextInput.test.tsxconflict keeps both sides.inputevent now lives in one internalsetInputValue(inpackages/core/src/utils/, not exported from the package). TextInput's clear and Typeahead's edit-mode entry and clear call it; Typeahead's behavior is unchanged.