Skip to content

fix(core): taps that start typing raise the touch keyboard - #8158

Merged
cixzhang merged 3 commits into
meta:mainfrom
vjeux:uikit/c09-typeahead-edit-focus
Oct 24, 2026
Merged

cixzhang merged 3 commits into
meta:mainfrom
vjeux:uikit/c09-typeahead-edit-focus

Conversation

@vjeux

@vjeux vjeux commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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":

(device capture removed: it showed browser chrome)

Searchable Selector, "ap" typed, keyboard dismissed, tap on clear:

(device capture removed: it showed browser chrome)

  • 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

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • 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.

@vercel

vercel Bot commented Oct 24, 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 Oct 24, 2026 12:57pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 24, 2026, 1:24 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 24, 2026
@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

46 of 494 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 753,933
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,072
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
RichTextEditor Markdown parity: side by side probe dark 94,866
RichTextEditor Markdown parity: side by side probe light 89,762
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 36,304
Chat Default neutral light 35,767
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
Markdown Default neutral dark 7,573
Markdown Default neutral light 7,566

and 26 more.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

@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 — 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)) because input.focus = … throws once an earlier test in the file has called userEvent.setup() (user-event 14.6.1 makes HTMLElement.prototype.focus getter-only), so install the spy with Object.defineProperty as 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, with debounceMs={0}, Enter commits the first of them (Grape becomes Apple); committing the query before focus(), for example with flushSync around the native set and the input dispatch, keeps the focus inside the tap and fixes it, and a hasEntriesOnFocus case in the new tests would cover it.

[Automated review]

)?.set;
nativeInputValueSetter?.call(input, value.label);
input.dispatchEvent(new Event('input', {bubbles: true}));
input.focus();

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 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) => {

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

vjeux added 2 commits October 24, 2026 02:52
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.

@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 — 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();

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

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

@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 — 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']);

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.

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.

@cixzhang
cixzhang merged commit ad8af75 into meta:main Oct 24, 2026
63 of 64 checks passed
@vjeux
vjeux deleted the uikit/c09-typeahead-edit-focus branch October 24, 2026 14:05

This branch was successfully deployed

1 active deployment
Preview — 3216ad9c Deployed Oct 24, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants