Repository navigation
fix(core): taps that start typing raise the touch keyboard - #8158
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewNo new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression46 of 494 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 26 more. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
There was a problem hiding this comment.
Thanks — focusing inside the tap is the right fix for the iOS keyboard, but two issues need fixing before this can land:
- The two new Typeahead edit-mode tests fail in CI (
test-ui (1/4)) becauseinput.focus = …throws once an earlier test in the file has calleduserEvent.setup()(user-event 14.6.1 makesHTMLElement.prototype.focusgetter-only), so install the spy withObject.definePropertyas the new Selector test does. - With
hasEntriesOnFocus,BaseTypeahead's focus handler now runs before its query update renders, so tapping the selected value opens the bootstrap entries and, withdebounceMs={0}, Enter commits the first of them (Grape becomes Apple); committing the query beforefocus(), for example withflushSyncaround the native set and theinputdispatch, keeps the focus inside the tap and fixes it, and ahasEntriesOnFocuscase in the new tests would cover it.
[Automated review]
| )?.set; | ||
| nativeInputValueSetter?.call(input, value.label); | ||
| input.dispatchEvent(new Event('input', {bubbles: true})); | ||
| input.focus(); |
There was a problem hiding this comment.
This focus() now runs before BaseTypeahead renders the setQuery(label) queued by the input dispatch above, so its handleFocus → openIfEligible sees query === '' and, with hasEntriesOnFocus, calls performBootstrap(). With debounceMs={0} the bootstrap entries replace the label's match and Enter commits the first one (Grape becomes Apple). Committing first keeps the focus inside the tap:
flushSync(() => {
nativeInputValueSetter?.call(input, value.label);
input.dispatchEvent(new Event('input', {bubbles: true}));
});
input.focus();The comment above ("the base's focus handler sees the label") would then hold.
| // The event the browser is dispatching when focus() runs. | ||
| const focusedDuring: (string | undefined)[] = []; | ||
| const focus = input.focus.bind(input); | ||
| input.focus = (options?: FocusOptions) => { |
There was a problem hiding this comment.
This assignment throws TypeError: Cannot set property focus of [object HTMLElement] which has only a getter in the full file and in CI's test-ui (1/4): earlier tests call userEvent.setup(), and user-event 14.6.1 redefines HTMLElement.prototype.focus as a getter-only accessor. Object.defineProperty(input, 'focus', {configurable: true, value(options?: FocusOptions) { ... }}), as the new Selector test does, works.
Entering edit mode set the label, focused the input and selected the text in an animation frame. iOS raises its keyboard only for a focus made while the browser still dispatches the user's tap (or while the keyboard is already up), so the deferred focus left a caret with no keyboard. The edit now happens inside the tap's own dispatch.
…yboard PanelSearchInput deferred its refocus after a pointer clear to an animation frame, so on iOS a clear tapped while the keyboard was down focused the input without a keyboard. A UIKit search field's clear button makes the field first responder (keyboard included, measured on iOS 26.2). The refocus now runs inside the tap, with preventScroll for pointer taps; with the input already focused the clear button never takes focus, so the keyboard stays put.
212a0d2 to
39c93ba
Compare
There was a problem hiding this comment.
Thanks — the focus-spy fix gets the new tests passing, but the hasEntriesOnFocus regression raised in the earlier review is still present on this head. handleEnterEditMode calls focus() before BaseTypeahead has rendered the setQuery(label) queued by the input dispatch, so tapping the selected value opens the bootstrap entries and, with debounceMs={0}, Enter commits the first one (Grape becomes Apple). Committing the query first, for example with flushSync around the native set and the input dispatch, keeps the focus inside the tap and fixes it; please also add a hasEntriesOnFocus case to the new edit-mode tests and correct the comment above focus().
[Automated review]
| )?.set; | ||
| nativeInputValueSetter?.call(input, value.label); | ||
| input.dispatchEvent(new Event('input', {bubbles: true})); | ||
| input.focus(); |
There was a problem hiding this comment.
This focus() still runs before BaseTypeahead renders the setQuery(label) queued by the input dispatch above, so its onFocus → openIfEligible sees query === '' and, with hasEntriesOnFocus, bootstraps; with debounceMs={0} Enter then commits the first bootstrap entry (Grape becomes Apple). Committing first keeps the focus inside the tap:
flushSync(() => {
nativeInputValueSetter?.call(input, value.label);
input.dispatchEvent(new Event('input', {bubbles: true}));
});
input.focus();The comment above ("the base's focus handler sees the label") would then hold.
…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.
…p focus
With hasEntriesOnFocus, focusing before the base rendered the label opened
the bootstrap entries, and with debounceMs={0} Enter committed the first of
them. flushSync commits the query first, and the focus stays inside the tap.
There was a problem hiding this comment.
Thanks — this head fixes both earlier findings: flushSync commits the label before the in-tap focus, so a hasEntriesOnFocus Typeahead keeps searching its label on edit, and the new hasEntriesOnFocus test pins it. The change looks ready; the only red check, pr-a11y, runs a spec that main added after this branch's base, so a rebase onto main should clear it. Optionally, asserting {preventScroll: true} in the new Selector clear test would pin the only remaining guard against the #5422 scroll jump.
[Automated review]
| // No frame has run: the focus is in place when the tap's dispatch returns. | ||
| expect(search).toHaveValue(''); | ||
| expect(search).toHaveFocus(); | ||
| expect(focusedDuring).toEqual(['click']); |
There was a problem hiding this comment.
Optional hardening: with the frame gone, {preventScroll: true} is the only guard against the #5422 scroll jump, and dropping it from PanelSearchInput leaves every Selector, MultiSelector and Field test green. Recording the options in the spy above as well, for example focusedDuring.push([window.event?.type, options]) expecting [['click', {preventScroll: true}]], would pin it, as #8183 does for TextInput and NumberInput.
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:
Problem and solution fit
Both now focus inside the tap's own dispatch (the clear with
preventScrollfor a pointer tap).Expected behavior and authority
component:TypeaheadFR1 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:handleEnterEditModeruns its existing steps without therequestAnimationFrame.PanelSearchInput.tsx:handleCleardrops 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":
(device capture removed: it showed browser chrome)
Searchable Selector, "ap" typed, keyboard dismissed, tap on clear:
(device capture removed: it showed browser chrome)
Scope
Testing
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.