Skip to content

feat(useCombobox): a combobox over a text field the caller renders - #7732

Merged
cixzhang merged 15 commits into
meta:mainfrom
vjeux:combobox-hooks
Oct 28, 2026
Merged

cixzhang merged 15 commits into
meta:mainfrom
vjeux:combobox-hooks

Conversation

@vjeux

@vjeux vjeux commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

User need

Why: Keyboard and screen-reader users need pickers in fields a product already renders, like a settings search. Typeahead brings its own input and popup, so products hand-wire them, getting focus, keys or the spoken count wrong.

What led to it: One product we're moving onto Astryx hand-wires six (#7326).

Problem and solution fit

useCombobox meets spec:AST-075 FR1–FR6 for a single-line input the caller renders: roles, keys, input-method guard and pointer. ArrowDown reopens a hidden list (DEC-3). Multi-line fields and the hook-level result count (FR7) follow in their own pull requests; until then callers announce counts with useAnnounce.

Current specification

spec:AST-075 (current), DEC-1–DEC-3; its Current-state impact says what ships. OQ2 (Home and End) and OQ3 (grids) stay open.

Public delta and caller burden

Additive; Selector, CommandPalette and other callers are unchanged.

const combobox = useCombobox({selectableItems, isOpen, onOpen, onClose, listboxId, onSelect});
<input {...combobox.getFieldProps({onKeyDown})} /> // list: getListboxProps(); rows: getOptionProps(i)

Design and alternatives

Options and tradeoffs (DEC-2): a new component, or BaseTypeahead taking a caller's field, suits common cases but locks behavior in one component's markup; generalizing useCombobox makes callers spread getters and own the open state.

Why this choice: Selector and CommandPalette already use it, so one tested implementation backs every surface and released options keep working. Chords like Shift+Enter stay the field's.

Size: 1,881 authored lines (additions plus deletions vs main, goldens excluded), under the 2,000-line limit.

Evidence

Spec, unit, types, Chromium, stories.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

R1–R6: no findings.

Testing

Head 8d618de on current main; per-PR CI runs Chromium only (b2c333b: 55 success, 8 skipped, none red).

How to check (useCombobox stories): Search Field: type "no": "2 results" is announced, and ArrowDown, Enter picks. Assignee Field: type "ar"; Escape hides only the layer. In Dialog: Escape hides the list, not the dialog.

Tests (each fails without its fix):

  • Unit: FR1–FR6; any-modifier Escape; Safari's keyCode-229 composition; ArrowDown reopening.
  • Types: ReturnType<typeof useCombobox> and an input-typed onKeyDown compile.
  • Chromium: contract plus axe in flow, in a layer and in a dialog; real keys and pointer; Escape and Shift+Escape; stories announce each new query once, never on mount, In Dialog in its own region.
  • Safari: WebKit 26.5 trusted keys and iOS-simulator taps passed on earlier heads; no desktop Safari.
  • Goldens move only count lines; the ui project, typecheck, ESLint, Prettier and check:repo pass.

@vercel

vercel Bot commented Oct 20, 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 28, 2026 9:05am UTC

Request Review

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

astracat-bot Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 28, 2026, 9:33 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 20, 2026
@vjeux

vjeux commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 2bf8f07

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 20, 2026
@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Component Size

Component Import before Import after Delta CSS before CSS after Delta
core/CommandPalette 51.5KB 51.9KB +418B 12.0KB 12.0KB 0B
core/Pagination 85.5KB 85.9KB +416B 15.5KB 15.5KB 0B
core/PowerSearch 166.0KB 166.5KB +450B 20.1KB 20.1KB 0B
core/Selector 77.0KB 77.5KB +433B 15.2KB 15.2KB 0B
core/SelectorOption 14.7KB 14.7KB 0B 5.2KB 5.2KB 0B
richtext/RichTextEditorToolbar N/A 213.4KB N/A N/A 454B N/A

Sizes are gzip. Import counts the JavaScript the import loads eagerly; CSS counts the package stylesheet rules referenced by the modules it can load from its own package, lazily loaded ones included.

Bundle Size Summary

Gzip figures measure each package's entry file, not the code an import pulls in.

Package Entry (ESM) Entry gzip before Entry gzip after Delta
@astryxdesign/core 4.9KB 1.2KB 1.2KB 0B
Package stylesheet Gzip before Gzip after Delta
@astryxdesign/core 35.1KB 35.1KB 0B

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

57 of 506 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
RichTextEditor Markdown parity: side by side probe dark 558,840
RichTextEditor Markdown parity: side by side probe light 540,756
Chat Full AI Chat probe light 230,823
Chat Full AI Chat probe dark 229,805
AppShell With Mobile Nav probe light 217,010
AppShell With Mobile Nav probe dark 216,960
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
AppShell Playground neutral dark 65,198
AppShell Playground neutral light 63,788
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

and 37 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 for building this against AST-075; the caller-rendered field support is close, but approval waits on two things. A maintainer needs to identify or provide the governing spec for one addition: AST-075 DEC-2 does not say whether the released onSelect callback may gain a second argument (onSelect(value, item)), so a maintainer should either confirm DEC-2 covers it and record that in AST-075, or keep onSelect(value). Separately, please fix the open-but-empty state: with isOpen true and no options, getFieldProps still claims ArrowUp, ArrowDown and Escape (packages/core/src/Selector/hooks.ts, line 540) while the field reports no list, so a textarea or contenteditable field stops moving its caret, which AST-075 FR4 rules out; gating those keys on the rendered listbox for multi-line fields, with tests for that state, resolves it. With both settled, the 2,069 authored lines can be justified under AST-075; otherwise the change needs to come in under 2,000 lines.

[Automated review]

Comment thread packages/core/src/Selector/hooks.ts Resolved
Comment thread packages/core/src/Selector/hooks.ts Resolved
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 20, 2026
@vjeux

vjeux commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 30ee961

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 20, 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: the caller-rendered field support now matches AST-075, including the multi-line keys fix and keeping onSelect(value), but one AST-009 step is missing before this can merge. The new query announcements (the result count and "No results found") are announcement content and timing under AST-009 FR4, so FR17 asks for a named real-AT matrix and scenario plus a durable release-block record before merge, as AST-009's Current-state impact already does for CommandPalette's empty-result announcement.

  • Name the NVDA + Chrome (Windows) and VoiceOver + Safari (macOS) rows and a scenario on one of the new stories, and add a pending release-block entry for this pull request to AST-009; the receipts themselves can follow before the first stable release.
  • In the InDialog story a query with no matches renders nothing but keeps the list open, so the first Escape does nothing visible; render an empty message as the other stories do (or keep isOpen false), and note in the hook doc that an open single-line field with no options still takes Escape.

[Automated review]

Comment thread packages/core/src/Selector/hooks.ts Resolved
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 20, 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.

This looks ready to approve: the caller-rendered field support in useCombobox matches AST-075, and both earlier points are resolved, with AST-009's pending release block for the new result-count announcement and a visible empty message in the InDialog story. What remains is an engineering owner's approval on this head, which now also edits AST-009, and the NVDA + Chrome and VoiceOver + Safari receipts that clear that block before the first stable release.

[Automated review]

cixzhang added a commit that referenced this pull request Oct 22, 2026
## Exact decision needed

Whether merge or stable release may wait on real assistive-technology (NVDA, VoiceOver) evidence that contributors cannot produce.

## Existing authority searched

- `spec:AST-009` (current): FR4/FR8/FR17–FR19 required an explicit trigger classification, a named real-AT matrix, a scenario, and a durable release-block record, and blocked the first stable release until real-AT receipts passed or an owner exception applied.
- Linked records that restated the block or required screen-reader checks: `spec:AST-001` (browser evidence and FR7 row), `module:Table/useTableRowStatus` AR6, `module:Table/useTableColumnResize` verification, `spec:AST-056` (browser evidence line), `spec:AST-021` (release boundary phrase), `spec:AST-086` (FR6 real-AT row and platform line), `component:FieldStatus` AR5 and its verification row, `spec:AST-020` FR6 ("real-AT contract").
- Open PRs that add release-block sections to AST-009: #7732, #7275, #7272. Under this record those sections are no longer needed.

## Decision

- No requirement gates merge or release on evidence that cannot be produced (Intent, FR17, DEC-4).
- Merge and stable release need only the unit, DOM, accessibility-tree, axe, and real-browser evidence the owning records require (FR17).
- Announcements are proved by their routing: which element or channel carries them, their text, urgency, and update count per occasion (FR4, FR19).
- Real-AT observation is recommended follow-up when an outcome depends on AT behavior, may be tracked in a public issue, and holds no pull request or release (FR1–FR6, FR18).
- A change with an AT-dependent claim says so and names its lower-layer evidence; no matrix, scenario, or release record is needed to merge (FR8).
- Evidence-layer boundaries, the representative matrix, failure handling, and durable receipts stay, scoped to when a real-AT check runs.
- The exception process (old FR23–FR26) is removed because nothing remains to except.

## Rejected alternatives

- Holding stable releases until named real-AT receipts pass: fixes for known accessibility defects stall when no contributor can run the required pairings.

## Claim scope and non-goals

Only the evidence bar for merge and release, and the status of real-AT observation. Component accessibility requirements, evidence-layer boundaries, and focus/announcement behavior stay with their owners.

## Evidence and implementation relationship

Status-announcement conformance PRs (#7869, #7870, #7871, #7892, #7900, #7910) stall on the old real-AT release-block requirement because nobody in the review loop can run NVDA or VoiceOver. No implementation is included.

## Writing rubric results

- R1 narration: none; present-tense rules throughout. The two earlier holds are described as current follow-ups.
- R2 research in the record: none.
- R3 evidence naming a change: none; the earlier hold sections that named pull requests are replaced by the facts (story names and claims).
- R4 rejected alternatives over one line or outside a decision: one per decision, one line each.
- R5 pull request or issue references remaining: none in AST-009 or the edited lines.
- R6 ruled open questions still listing options: none.

## Scope

- [x] This PR contains specification records only.
- [x] It records observable behavior and preserves equivalent internal implementations.
- [x] Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract.
- [x] Verification states the evidence layer and failure signal without prescribing CI job/workflow topology.
- [x] It records one intentional durable decision, not a rescue for a separable tagalong.
- [x] The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision.
- [x] Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them.
- [x] Public text and artifacts contain no internal Meta context.

## Validation

- `pnpm check:knowledge`
- Prettier
- `git diff --check`
@vjeux

vjeux commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec b01a736

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 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: the caller-rendered field support matches AST-075 and its unit and Chromium contract tests pass, but one compatibility fix is needed before approval. Retyping onItemSelect and onItemMouseEnter to the generic option type (packages/core/src/Selector/hooks.ts:254-255) breaks released callers that name the hook's result as ReturnType<typeof useCombobox> with an option type of their own; the same code compiles on main, and AST-075 DEC-2 promises released return fields keep working unchanged. Declaring the two handlers with method syntax (onItemSelect(item: T): void;) restores it.

  • getFieldProps({onKeyDown}) rejects a handler typed for HTMLTextAreaElement; method syntax for that parameter fixes it too.
  • The MessageField story's send-on-Enter checks only isComposing, so in Safari it sends when Enter commits an IME composition (keyCode 229); please add that check, since products will copy this example.

[Automated review]

Comment thread packages/core/src/Selector/hooks.ts Resolved
Comment thread packages/core/src/Selector/hooks.ts Resolved
@vjeux

vjeux commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 325630d

vjeux added 4 commits October 27, 2026 15:39
…r its announcement

The shared channel exposes an identical message written twice in one frame
once (spec:AST-086 FR9). Counting what it exposes therefore cannot see the
hook announcing twice per query, and when two keys landed in one frame,
"nop" and "nope" exposed a single "No results found", so the Chromium case
failed now and then.

- The result-count unit tests also record every call the hook makes to the
  announcer: exactly one per new non-empty query, none for a mount, an
  empty or unchanged query, or a hidden list. Announcing twice per query
  fails them.
- The Chromium case waits for each query's announcement before the next
  key: one update per new query, and a new query with the same words
  announces again.
The InDialog story called useCombobox above the Dialog it renders. An
announcement follows where the hook is called (spec:AST-086 FR14), so each
result count went to the page body, which the open modal hides.

- The story's field and its useCombobox call render from a component
  inside the Dialog, so the count lands in the dialog's own live region.
- The `query` doc, its dense doc and its JSDoc say a field inside a modal
  needs the call inside it, and that counts are announced while the list is
  open (`isOpen`), with or without a rendered listbox.
- A Chromium test records which polite region each count lands in: the
  dialog's own, never the page body's. It fails with the call above the
  Dialog.
…own on a hidden textarea list

With `query`, the hook announced a fixed "No results found" when nothing
matched, while the field showed its own words. The announced words must be
the shown words (spec:AST-086 FR7, spec:AST-056 FR3).

- New option `emptySearchText` (ReactNode, default "No results found"), the
  name and type Selector, Typeahead and CommandPalette ship. The hook returns
  it, and `getEmptyProps()` for the element that shows it.
- For a new query that matches nothing, the hook announces that element's
  rendered text through the shared helper Selector and Typeahead use. With
  no such element, a string is announced as it is; any other node warns in
  development, since nothing could be announced.
- The stories pass their own copy, or show the default, through
  `getEmptyProps`, and the doc says to render `emptySearchText` there.
- AST-075 FR7 adds that the words announced for none are the words shown.
- Unit and Chromium tests compare the shown and announced words, a link
  included; they fail when the catalog message is announced instead.
- The textarea journey also presses ArrowDown on the hidden list: the list
  stays hidden and the caret moves (DEC-3).
…the hook as an own-content adopter

- The empty-message announcement re-arms for every query after the one a
  field mounts with, a return to that first query included. It latches the
  first time the query differs from it, by adjusting state during render as
  CodeBlock does, so the mount itself stays silent. A unit test mounts with a
  no-match query, changes it and returns to it.
- useCombobox now imports the shared own-content module, so the INV10
  adopter test lists Selector/hooks.ts and checks that the hook hands its
  empty message to that module and announces none of it itself.
@vjeux

vjeux commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 2527a7a

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

Changes are needed for scope: at 2,986 authored lines this pull request is over the 2,000-line limit, and its hook-level FR7 announcement (query, emptySearchText, getEmptyProps, the two catalog messages, the FR7 sentence and their tests, about 850 lines) can land on its own, since AST-075 DEC-2 lets callers compose useAnnounce for the count. The caller-rendered field support itself matches AST-075, including the FR7 sentence approved for this head, and its unit, type and CLI tests pass with Selector and CommandPalette unchanged. Please move the FR7 layer into a follow-up pull request, or explain why it must ship with the FR1–FR6 field props.

[Automated review]

vjeux added 2 commits October 27, 2026 17:03
…ent layer

The hook-level result-count announcement moves to its own pull request:
`query`, `emptySearchText`, `getEmptyProps`, the two catalog messages, the
FR7 sentence in AST-075 and their tests. As AST-075 DEC-2 describes, callers
announce each new result count through `useAnnounce`, with the words the
field shows; the hook doc says so. The stories show plain empty messages.
The multi-line field moves to its own pull request: the `field` option
(`'textarea' | 'contenteditable'`), DEC-3's multi-line half, the Message
Field and Editable Field stories, and their Chromium, contract and unit
cases. This keeps a single-line `input` the caller renders: the getters,
FR1–FR6, and ArrowDown reopening a hidden list. AST-075's Current-state
impact says what ships.
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 28, 2026
@vjeux

vjeux commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec b2c333b

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 28, 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.

Changes are requested: the new useCombobox field getters match AST-075 for a single-line input, and the unit, type, CLI and Chromium tests pass with Selector and CommandPalette unchanged, but two gaps remain in what ships with them. Please make both new stories announce each new result count through useAnnounce (called inside the Dialog for In Dialog), since AST-075 FR7 and DEC-2 leave that to the caller and these stories are the examples products will copy. Please also add a story and a Chromium scenario where the input's listbox renders in a layer, a state AST-075's FR1–FR3 verification names.

[Automated review]

vjeux added 2 commits October 28, 2026 00:41
Main's icon changes (meta#8753, meta#8756, meta#8758, meta#8759) moved the `icon set` search
golden. Regenerated with `vitest run
packages/cli/test/experimental-isolation.test.mjs --update`: only the two
count lines differ from main.
…e list is in a layer

The Search Field and In Dialog stories announce each new query's result
count through useAnnounce, with the words they show for none, as AST-075 FR7
and DEC-2 leave to the caller; In Dialog calls it inside the Dialog, so the
count reaches the dialog's own live region. A new Assignee Field story renders
the input's list in a usePopover layer. The Chromium spec checks the Combobox
contract in that layer and both stories' announcements.
@vjeux

vjeux commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 8d618de

…aragraph

Since the In Dialog story announces its empty message, the dialog's own live
region holds the same words for a moment, so a page-wide text match found two
elements and failed in strict mode. The check now reads the paragraph inside
the dialog.

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

Changes are requested for one test fix: both points from the last review are resolved (the three stories now announce each new count through useAnnounce, and the new Assignee Field story covers a list in a layer), and the hook, the stories and the record edit match AST-075. The In Dialog empty-message journey still finds the message with page.getByText('No one matches', {exact: true}) (packages/core/src/Selector/__tests__/ComboboxField.a11y.chromium.spec.ts:294), which now also matches the dialog's polite live region, so it fails whenever the announcement lands first; CI's pr-a11y (browser specs) fails on it for this revision. Please scope that locator to the visible paragraph, as the search journey already does, for example page.locator('p').filter({hasText: /^No one matches$/}).

[Automated review]

@vjeux

vjeux commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 14651f2

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

This looks ready to approve: the new useCombobox field getters match AST-075 for a single-line input, the Current-state edit is owner-approved for this revision, and the last point from the previous review is resolved now that the In Dialog empty-message test reads only the shown paragraph. Unit, type, CLI discovery and Chromium tests pass on this revision with Selector and CommandPalette unchanged, so nothing else needs to change before merge.

[Automated review]

@cixzhang
cixzhang merged commit 6162917 into meta:main Oct 28, 2026
73 checks passed
@vjeux
vjeux deleted the combobox-hooks branch October 28, 2026 17:08
vjeux added a commit to vjeux/astryx that referenced this pull request Oct 28, 2026
The no-icon-set search goldens conflicted after main's meta#7732 moved the
"icon set" count; with this pull request's keyboard section the merged docs
return 370. Regenerated with the test's --update.
cixzhang pushed a commit that referenced this pull request Oct 30, 2026
…#8381)

## User impact

**Why:** Keyboard and screen reader users lose their place when a dialog inside an iframe closes: both ways to close it (2 of 2: Escape or a button) send focus to the frame's empty page.

**What:** The dialog now returns focus to the control that opened it, with a ring after a key, none after a click. Picture-in-Picture windows were already fine.

**How to check:** In the "Dialog in a second document" story, open the frame's dialog and press Escape: focus returns to "Open dialog", with its ring.

## Problem and solution fit

What led here: we hit this moving one product onto Astryx, which renders some UI in a second window. Dialog remembers its opener as the page's `document.activeElement`, which for focus inside an iframe is the `<iframe>`. Focusing that `<iframe>` on close moves the frame's focus to its `<body>`.

Options:

- Follow the page's active element into iframes: misses Picture-in-Picture windows, which the page cannot see into.
- Always read the dialog's own document: a page control opening a dialog inside an iframe would lose focus.
- Read the dialog's own document while it has focus, else the page's: covers both. Chosen.

For the ring, Dialog tracks its own document's input, which the page never hears. Skipping its focus call would change the page, where it hides WebKit's ring after a click.

## Expected behavior and authority

`component:Dialog` (current) FR4 and AR2: closing returns focus to the element that opened it. `architecture:interaction-modality` (current) INV1: programmatic focus shows the ring only after keyboard input. Neither is page-only; #7356 fixed this for Popover.

## Smallest restoration

- `Dialog.tsx`: record the opener as above, take the entry direction from its window, return focus with its document's modality.
- Internal utils: `trackInteractionModalityIn(doc)`, counted so the last mounted Dialog removes its listeners; an optional document for `getInteractionModality`; an optional modality for `focusForLastInput`, which checks text fields against their own window. The page's tracker and other callers are unchanged.

No public API, visual or timing change.

## Evidence

- Reproduction before the change: main fails the iframe cases in Chromium and WebKit.
- Result after the change: every case passes.
- Representative unchanged path: the page Dialog passes before and after; the page's modality ignores other documents.
- Regression test or other mutation-sensitive proof: the Testing cases, red without the fix.

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

- Unit tests (Vitest), 115 files and 3137 tests: Dialog and every other component that returns focus or reads the last input. New cases cover a control inside an iframe, a control in the page, a text field, and the input listeners going away when the last Dialog unmounts. Each new case fails on the code from before the fix it covers.
- Browser test in Chromium, 10 cases (`DialogSecondDocument.a11y.browser.spec.ts`): the dialog in the page, an iframe and a Picture-in-Picture window, closed with Escape, with a click, and after a text field opened it, plus a page button that opens a dialog in the iframe. All pass. With the code from before the last review round (0d47027), the iframe and Picture-in-Picture text-field cases fail; with main's `Dialog.tsx`, the iframe cases fail.
- The same test in WebKit 26.5: 7 pass, and the 3 Picture-in-Picture cases are skipped, since only Chromium has that window.
- CI finds the test by its file name (#8367), and its routing line also covers its story and the two utilities. Locally, `pnpm test:a11y-contract:pr origin/main` picks it and passes 115 browser tests.
- Typecheck, repo checks, ESLint and Prettier pass. Merged with our open #7732, #8014 and #7524, typecheck and the utility tests (516) pass; #7525, #7527 and #7529 each merge cleanly with this change.
cixzhang pushed a commit that referenced this pull request Oct 31, 2026
…8543)

CI note: this head's checks were blocked by the repository's Actions policy (no jobs ran since 17:43Z); they need a re-run.

## Why, what, how to check

**Why.** This comes from one product's effort to get its production JavaScript errors to zero: its log shows this one 12 times from 5 people in 7 days (9 on WebKit, 3 on Chrome). Pressing Escape inside an open popover throws it: the browser closes the popover and returns focus to its button, the tooltip there asks to open while the close still runs, and Chromium 151 and 156 refuse (149 does not). The tooltip stays closed.

**What led here.** The Popover API refuses a show while any popover shows or hides, and a hide returns focus inside that window. #6941 makes a show wait while `useLayer` runs its own show or hide; a close the browser runs itself (Escape, a tap outside) never entered that bookkeeping.

**Options.** (a) Catch the error and drop it: hides a real failure, and the tooltip still never opens. (b) Wait out every browser close before any show: tried first; it delayed a press that closes one menu and opens another, so focus no longer moved into the new menu. (c) Count the browser's close, try the show at once, retry after the close only if the browser refused. Chosen: it fixes the Escape case and keeps every other path as fast as before.

**What.** `useLayer` counts the browser's own popover closes in its ledger, from the close's start to its `toggle` event; a show refused during one replays after it, once.

**How to check.** Storybook `Core/Layer` → `BrowserHideWakesAFocusLayer`, Chromium 151+: Tab, Enter, Tab, Escape. Before: `InvalidStateError` in the console, no tooltip. After: no error, the tooltip shows.

## Expected behavior and authority

`architecture:layer-runtime` (current): browser-initiated closes are observed through the queued `toggle` event; that holds. Restored: #6941.

## Smallest restoration

- `popoverOperations.ts` holds the ledger `useLayer.tsx` kept privately, plus the browser-close count and the replay, tested alone there. No public API, default, record or visual change.

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

- Unit tests for Layer, its ledger, Tooltip, DropdownMenu, Popover, Drawer and Selector: 7 files, 652 passed. Without the fix, `useLayer.test.tsx` "defers the show a browser-run hide wakes…" and "keeps counting…" fail; with option (b), "opens a layer at once…" fails; `popoverOperations.test.ts` "ends each hide exactly once…" fails without `clearTimeout`.
- Type check, repository checks, lint, formatting: clean.
- Browser spec `LayerBrowserHide.a11y.chromium.spec.ts` (3 cases) on this branch's Storybook build: 3 passed. CI's Playwright runs Chromium 149, which allows these shows, so there the spec passes on main too. On Chromium 156 the story's steps throw `InvalidStateError … during another show operation` on main, tooltip hidden, and show it with no error here; a tap outside closes the layer with no error on both; the press that closes one layer and opens another focuses the new one at once.
- Open PRs #7732, #8381 and #8014 touch nothing under `packages/core/src/Layer/`; a trial merge with #7732 is clean; the other two conflict with main on their own.

This branch was successfully deployed

1 active deployment
Preview — 14651f27 Deployed Oct 28, 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