Repository navigation
fix(core): defer clear focus restoration out of tap to prevent touch page scroll jump - #5440
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsDateInput (@astryxdesign/core) · View in Storybook
DateTimeInput (@astryxdesign/core) · View in Storybook
Field (@astryxdesign/core) · View in Storybook
FileInput (@astryxdesign/core) · View in Storybook
NumberInput (@astryxdesign/core) · View in Storybook
TextInput (@astryxdesign/core) · View in Storybook
TimeInput (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: 1 accessibility violation(s) found — 1 serious. FileInput - 1 issue(s)
Visual RegressionStatus: No visual change across 16 compared shot(s). Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
left a comment
There was a problem hiding this comment.
Touch clearing keeps TextInput focused and scroll-stable in Chromium, but keyboard users now lose focus to the document for one frame before the input is restored. The base kept focus on the input before click bubbling and the first animation frame. Please preserve that keyboard path while deferring only the pointer/touch path, with focused regression coverage.
This head also no longer integrates with current main: the synthetic merge conflicts in DateTimeInput and TimeInput and produces duplicate onPointerDown props in InputClearButton, colliding with the current popup-aware handler. Please rebase and compose the current handler so touch clearing stays scroll-stable without dropping current popup behavior.
[Reviewed by Robohands]
…e InputClearButton onPointerDown
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, this fixes both prior issues. Chromium keeps keyboard focus and touch scroll stable, and Selector/MultiSelector popups stay open when cleared.
[Reviewed by Robohands]
…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.
## User impact On an iPhone, two taps that should start typing put a caret in the field but no keyboard, so a second tap is needed: - a tap on a Typeahead's selected value, which turns it back into editable text (edit mode); - a tap on the clear button of a Selector or MultiSelector search row after the keyboard was dismissed. ## Problem and solution fit 1. Why it occurs: both focus the input in an animation frame after the tap. iOS raises its keyboard only for a focus made while the browser is still handling the tap, or while the keyboard is already up. 2. Why it harms the task: the field looks ready for typing but there is nothing to type with. 3. Why it matters: the tap meant to start a correction or a new search seems to do nothing. Both now focus inside the tap's own dispatch (the clear with `preventScroll` for a pointer tap). ## Expected behavior and authority `component:Typeahead` FR1 makes the editing state an editable input. For the clear button the reference is UIKit: tapped while the field is not editing, a search field's clear button makes it first responder, keyboard included (iOS 26.2 simulator). #5440 deferred the clear's refocus against a page scroll jump on iOS. With `preventScroll`, a page scrolled to 668 px stays there through the clear on iOS 26.2, keyboard down or up. Other clearable fields keep #5440's deferral (a separate fix). ## Smallest restoration `Typeahead.tsx`: `handleEnterEditMode` runs its existing steps without the `requestAnimationFrame`. `PanelSearchInput.tsx`: `handleClear` drops the deferred branch. No API, style or layout change. ## Evidence iOS 26.2 simulator, Mobile Safari, real taps, keyboard down before the tap; left: main, right: this branch. Typeahead, tap on the selected value "Apple":  Searchable Selector, "ap" typed, keyboard dismissed, tap on clear:  - Before: the input is focused, no keyboard (inset 0). - After: the input is focused and the keyboard is up (inset 337 px); typing fills the field. - Unchanged: a clear with the keyboard up keeps it up; the scroll position. - Regression tests: three cases check that focus runs while the click is dispatched; all fail on the parent commit. ## 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 -F @astryxdesign/core typecheck pnpm exec vitest run packages/core/src/Typeahead packages/core/src/InputGroup packages/core/src/Selector packages/core/src/MultiSelector packages/core/src/Field pnpm storybook:build ``` Real-browser states: iOS 26.2 simulator (iPhone 17 Pro), Mobile Safari, real taps and typing, on main and on this branch: the Typeahead default story (pick "Apple", blur, tap the value); the searchable Selector story (open, type, blur, tap clear; type again, tap clear with the keyboard up), once at the top of the page and once with the page scrolled to 668 px. Focus, the visual viewport and the scroll position read after each tap.
Summary
Fixes #5422
Following up on #5350 (which fixed
TouchDateField), this PR extends the deferred focus restoration pattern across all clearable input controls (DateInput,DateTimeInput,PanelSearchInput,FileInput,TextInput,NumberInput,TimeInput) that consumeInputClearButton.Cause
When clearing an input value via
InputClearButtonon mobile WebKit/iOS Safari:<InputClearButton>(which is conditionally rendered whenvalueis set)..focus()synchronously on the target input within the same task while processing the touch tap causes iOS Safari to jump the document scroll position to0(scrollTop: 0).The Fix
.focus({preventScroll: true})inrequestAnimationFrameacross all clearable input components (DateInput,DateTimeInput,PanelSearchInput,FileInput,TextInput,NumberInput,TimeInput).onPointerDown/onMouseDownwithpreventDefault()onInputClearButtonto prevent pointer events from stealing focus from the input field prior to clearing.Test Plan
300/300tests passed acrossInputClearButton,DateInput,DateTimeInput,FileInput,TextInput,NumberInput,TimeInput).0errors..changeset/defer-clear-focus-tap.md(node scripts/check-changesets.mjspassed).