Skip to content

fix(TextInput): dispatch changeAction and update optimistic value on clear - #6425

Merged
cixzhang merged 3 commits into
meta:mainfrom
ManoharPaturi:fix/text-input-clear-change-action
Nov 9, 2026
Merged

cixzhang merged 3 commits into
meta:mainfrom
ManoharPaturi:fix/text-input-clear-change-action

Conversation

@ManoharPaturi

@ManoharPaturi ManoharPaturi commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Real change event on clear. The clear button now goes through the input's own change handler (a native value set plus an input event, as Typeahead already does), so onChange and changeAction get a real ChangeEvent whose target is the input. An Action that reads e.target no longer throws on clear. onChange runs first, and its preventDefault() cancels the Action, as it does for typing.
  • Tests: the clear tests check the event's target and that onChange runs before changeAction. A new case checks that preventDefault() in onChange stops the Action. The optimistic empty value and busy state case is kept.
  • Main merged; the TextInput.test.tsx conflict keeps both sides.
  • One shared helper. The native value set plus input event now lives in one internal setInputValue (in packages/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.
  • Records: the TextInput record (FR5's gap, readiness and Current-state) and the input-fields family drop the clear-skips-the-Action gap this PR closes.
  • TextInput, Typeahead and Tokenizer suites pass (575 tests), and Table filtering, PowerSearch, InputGroup and SearchInput pass (594).

Copilot AI lite review requested due to automatic review settings September 21, 2026 18:23
@vercel

vercel Bot commented Sep 21, 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 Nov 9, 2026 5:58am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@astracat-bot

astracat-bot Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 9, 2026, 6:06 AM UTC

@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 21, 2026
github-actions Bot added a commit that referenced this pull request Sep 21, 2026
@github-actions

github-actions Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 695d364

Storybook · Sandbox · built from this PR's head

Modified components

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]>
@ManoharPaturi
ManoharPaturi force-pushed the fix/text-input-clear-change-action branch from 88ff5af to 6358f27 Compare September 22, 2026 01:45
github-actions Bot added a commit that referenced this pull request Sep 22, 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 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]

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

Copy link
Copy Markdown
Contributor Author

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
@cixzhang cixzhang added ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) labels Nov 9, 2026
@cixzhang cixzhang closed this Nov 9, 2026
@cixzhang cixzhang reopened this Nov 9, 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 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-470 adds a third copy of the native value-set and input-event code that Typeahead.tsx already has twice (:516-523 and :589-597); please move it into one shared helper under packages/core/src/utils/ and call it from TextInput's handleClear and 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.
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

/approve-spec 695d364

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

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]

@github-actions github-actions Bot removed the needs:code-review High-risk change (new package/component/API) — needs human code review before merge label Nov 9, 2026
@cixzhang
cixzhang merged commit bb07866 into meta:main Nov 9, 2026
81 checks passed

This branch was successfully deployed

1 active deployment
Preview — 695d3644 Deployed Nov 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants