Skip to content

feat(Typeahead): add a controlled API to set or clear the typed query - #11526

Open
mvanhorn wants to merge 12 commits into
meta:mainfrom
mvanhorn:feat/typeahead-controlled-query
Open

mvanhorn wants to merge 12 commits into
meta:mainfrom
mvanhorn:feat/typeahead-controlled-query

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Nov 13, 2026 •

Copy link
Copy Markdown

feat(Typeahead): add a controlled API to set or clear the typed query

Related to #8930

Animated replay of real captured command output, not a live UI recording. Live Testing Library capture at 3:24 AM PT, Fri Nov 13, 2026 (America/Los_Angeles). Re-run at 3:26 AM PT: 469 tests passed.

demo

User need

An app can watch the typed search through onChangeQuery, but it cannot set that text. Filters, restored sessions, and sibling controls need to put a query in the field, or empty it, without taking over selection (value / onChange). Today the text lives only in BaseTypeahead state, so those apps reimplement the input or fight a pick that clears it.

A wrapper cannot fill the gap: the engine owns search, the listbox, and the announcements. The app needs the same controlled pair other Astryx fields already use.

Problem and solution fit

Add optional query and defaultQuery on Typeahead, Tokenizer, and BaseTypeahead, next to the existing onChangeQuery.

  • Pass query to show that text. onChangeQuery keeps reporting every change, its own included, so a controlled field stays in sync.
  • Hold query after a pick to keep the text. Follow onChangeQuery('') to empty it.
  • Pass defaultQuery when the field should start with text and then own it.
  • Omit both and the field still owns an empty string, as it does today.
  • Setting query from outside does not move focus. It does not open the listbox or announce a result count unless the field has focus. Clearing query while the field is focused does what emptying the field does: the listbox closes, or shows the focus entries with hasEntriesOnFocus.

Current specification

component:BaseTypeahead FR1 describes the input as internal query state while value is caller-controlled, and a pick as clearing that query. component:Typeahead records value as the controlled selection. Neither record names a public query / defaultQuery pair.

This pull request keeps that default: omit query and the field still owns the text, and an uncontrolled pick still empties it. The new props are additive. Owner review can admit them on those records.

Related to #8930.

Public delta and caller burden

API

const [query, setQuery] = useState('');

<Typeahead
  label="Assignee"
  searchSource={userSource}
  value={assignee}
  onChange={setAssignee}
  query={query}
  onChangeQuery={setQuery}
/>

<button type="button" onClick={() => setQuery('Ada')}>
  Search Ada
</button>
<button type="button" onClick={() => setQuery('')}>
  Clear search
</button>
<Tokenizer
  label="Labels"
  searchSource={labelSource}
  value={labels}
  onChange={setLabels}
  defaultQuery="bug"
  onChangeQuery={setQuery}
/>
  • New optional query?: string. When set, the field is controlled and shows this text.
  • New optional defaultQuery?: string. Initial text when query is not set.
  • Existing onChangeQuery keeps reporting every change, its own included, so a controlled field stays in sync.
  • value / onChange are unchanged: they are still the selected item or tokens.
  • No theming attributes change.
  • Accessibility: an idle set does not move focus, open the listbox, or announce a count. A focused clear does what emptying the field does: the listbox closes, or shows the focus entries with hasEntriesOnFocus.

Caller decision: pass query with onChangeQuery to own the text. Pass defaultQuery to start with text the field then owns. Omit both to keep today's empty internal query.

First-load size

Eager gzip per entry, base (12a96e4) against head, measured with the measureEntry build from scripts/check-component-import-boundaries.mjs:

Page with Base Head Delta
Typeahead 85,298 B 85,533 B +235 B
Tokenizer 101,271 B 101,528 B +257 B
BaseTypeahead 75,544 B 75,752 B +208 B
Text, Heading, Button, IconButton, Link, Table unchanged unchanged 0 B

The growth is the controlled-query wiring in the shared BaseTypeahead module.

Design and alternatives

  • Controlled query with uncontrolled defaultQuery. Matches isOpen / defaultIsOpen and other Astryx fields. Chosen so an app can restore, clear, or keep text without a breaking default.
  • Drive the text only through a handle. Rejected: a handle cannot keep a controlled React tree in sync, and a pick would still empty the field behind the app.
  • Reuse value for the typed text. Rejected: value is the selected item. Mixing selection and typing would break every existing callsite.

A search the app starts while the field is idle reuses the dismissed-search path: the answer is kept for the next open, the listbox stays closed, and the live region stays quiet.

Evidence

  • query shows on Typeahead, Tokenizer, and BaseTypeahead, and typing reports through onChangeQuery.
  • The app can set query="" and the field empties.
  • An idle set does not steal focus or open the listbox, and it does not announce a result count.
  • A focused clear does what emptying the field does: the listbox closes, or shows the focus entries with hasEntriesOnFocus.
  • A controlled pick reports '' and keeps the text when the app holds query.
  • An uncontrolled pick still empties the field. defaultQuery shows without opening the listbox, and the field still types after it.

Docs: Typeahead.doc.mjs, Tokenizer.doc.mjs, BaseTypeahead.doc.mjs.

Scope

Components: Typeahead, Tokenizer, BaseTypeahead

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

Testing

pnpm exec vitest run \
  packages/core/src/Typeahead/BaseTypeahead.test.tsx \
  packages/core/src/Typeahead/Typeahead.test.tsx \
  packages/core/src/Tokenizer/Tokenizer.test.tsx \
  packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx \
  --project ui

473 tests passed in those files (including the new controlled-query cases).

Lint/format on touched files. Pre-existing unused composeEventHandlers import warning in Typeahead.tsx is unchanged.

State matrix: controlled vs defaultQuery vs omit, set and clear from outside, idle vs focused, pick-sync (hold vs empty), Typeahead / Tokenizer / BaseTypeahead, listbox open/close, live-region result count.

@vercel

vercel Bot commented Nov 13, 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 Dec 4, 2026 5:50am UTC

Request Review

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

astracat-bot Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Dec 4, 2026, 6:10 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 Nov 13, 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.

Approval waits on an engineering owner's decision about the new public API, and four fixes are needed.

No current spec covers the controlled query / defaultQuery pair: the BaseTypeahead spec says the query text is internal and that a pick clears it. An engineering owner needs to decide whether to admit the pair, and how a controlled pick, a value set while the field is idle, a focused clear and the Tokenizer sheet's close should behave. They record it by commenting /approve-spec <full head SHA> (the author may do so if they are an engineering owner) or by updating the records.

Blocking findings:

  • When the app echoes onChangeQuery into query (the documented usage), the pick's reported '' runs the outside-change path (BaseTypeahead.tsx:1806-1813 and :1728-1733). That drops Tokenizer's "Added …" announcement and, with hasEntriesOnFocus, reopens the list right after the pick. Please fix it and add tests for that echo path.
  • queryRef.current = query (BaseTypeahead.tsx:921) and sheetQueryRef.current = queryProp (Tokenizer.tsx:1211-1213) write refs during render, which react-component-runtime INV17 forbids. Both can be deleted, because the handler and the sheet's press already read the current value.
  • The new query layout Effect (BaseTypeahead.tsx:1728-1733) does not name the external system it synchronizes, and its set-state-in-effect disables give no justification (INV3).
  • The description and changeset present onChangeQuery's reports for a pick, a clear and entering edit mode as new, but the base already makes all three. Please reword them so the release note does not announce a change.
Claims and files checked

Claims:

  • Adds optional query and defaultQuery to Typeahead, Tokenizer and BaseTypeahead: verified (Typeahead.tsx:232, :236; Tokenizer.tsx:341, :345; BaseTypeahead.tsx:261, :266).
  • Passing query shows that text, and typing reports through onChangeQuery: verified (test "shows a query the app sets and reports typing", all three components).
  • Holding query after a pick keeps the text: verified (test "keeps the text after a pick when the app holds the query").
  • Following onChangeQuery('') empties the field after a pick: partly false. It empties, but drops Tokenizer's "Added" announcement and, with hasEntriesOnFocus, reopens the list (Chromium and unit probes).
  • defaultQuery starts the field with text the field then owns: verified (tests "shows defaultQuery without opening the listbox", "lets an uncontrolled field type after defaultQuery").
  • Omitting both keeps today's behavior: verified (the four named suites pass on the head; the uncontrolled path is unchanged).
  • A value set from outside does not move focus, open the list or announce a count unless the field has focus: verified (test "does not move focus or open the listbox…"; Chromium probe).
  • A focused clear closes the list as emptying the field does: verified (test "closes the listbox when the app clears the query while the field is focused"; BaseTypeahead.tsx:1656-1689).
  • A search the app starts while the field is idle keeps its answer for the next open: verified (BaseTypeahead.tsx:1252-1265, :1375-1380; a probe that focuses afterwards shows the results).
  • onChangeQuery now reports a pick, a clear and entering edit mode: false. The base already reports all three (base BaseTypeahead.tsx:1736, base Typeahead.tsx:524 and its synthetic input event, base handleClear).
  • value / onChange and theming are unchanged: verified (diff; the API generator lists only the six added props).
  • The pair follows the isOpen / defaultIsOpen pattern of other fields: verified (Collapsible.tsx:247, :253).
  • 469 tests pass in the four named files: verified (re-run on the head).
  • The changeset's patch bump matches its [feat] category: verified against the contribution guide.

Files:

  • .changeset/typeahead-and-tokenizer-add-a-controlled-api-to--l7mf.md: finding (claim wording).
  • packages/core/src/Typeahead/BaseTypeahead.tsx: findings (echoed pick, render-time ref write, Effect note).
  • packages/core/src/Tokenizer/Tokenizer.tsx: finding (render-time ref write).
  • packages/core/src/Tokenizer/TokenizerBottomSheet.tsx: clear.
  • packages/core/src/Typeahead/Typeahead.tsx: clear.
  • packages/core/src/Typeahead/BaseTypeahead.test.tsx: gap (no test echoes onChangeQuery into query).
  • packages/core/src/Typeahead/BaseTypeahead.doc.mjs, Typeahead.doc.mjs, packages/core/src/Tokenizer/Tokenizer.doc.mjs: clear (they match the JSDoc).

Automated review (maintainer link)

Record the empty query a controlled pick reports so echoing it
back into query does not re-run the external path. That path
cleared the Added announcement and, with hasEntriesOnFocus,
bootstrapped the list open again. A held query after a pick
is left alone.

Drop render-time writes on queryRef and sheetQueryRef. Name
the INV3 systems the query-prop layout effect synchronizes.

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

Approval waits on an engineering owner's decision about the new public API, and two wording fixes are needed; the four fixes asked for in the last review are in.

No current spec covers the controlled query / defaultQuery pair: the BaseTypeahead spec says the query text is internal and that a pick clears it. An engineering owner needs to decide whether to admit the pair, and how a held query after a pick, a value set while the field is idle, a focused clear and the Tokenizer sheet's close should behave; they record it by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner) or by updating the records.

Blocking findings:

  • Miss: the new query docs (Typeahead.doc.mjs:257, BaseTypeahead.doc.mjs:246, Tokenizer.doc.mjs:216 and the matching Chinese entries) and the description say a focused clear closes the listbox, but with hasEntriesOnFocus it shows the focus entries (BaseTypeahead.tsx:1659-1661), so please reword them to say it does what emptying the field does: the listbox closes, or shows the focus entries with hasEntriesOnFocus.
  • The description still says onChangeQuery "now reports" a pick, a clear and entering edit mode, which the base already does, so please reword it the way the changeset now reads.

Two smaller points: Tokenizer's docs list "entering edit mode", which Tokenizer does not have, and a test with default props that echoes the pick and asserts the "Added …" announcement would cover the other half of the echo fix.

Claims and files checked

Claims:

  • Adds optional query and defaultQuery to Typeahead, Tokenizer and BaseTypeahead: verified (Typeahead.tsx:232, :236; Tokenizer.tsx:341, :345; BaseTypeahead.tsx:261, :266).
  • Passing query shows that text, and typing reports through onChangeQuery: verified (test "%s shows a query the app sets and reports typing", all three components).
  • The field reports a pick, a clear and entering edit mode through onChangeQuery: verified, and already true on the base.
  • onChangeQuery "now" reports those changes: false; the base already reports all three (base BaseTypeahead.tsx:1736, base Typeahead.tsx:524, base Typeahead.tsx:614-617).
  • Holding query after a pick keeps the text: verified (test "keeps the text after a pick when the app holds the query").
  • Following onChangeQuery('') empties the field after a pick: verified (new Tokenizer echo test; in a browser the field empties, the list stays closed and "Added …" is announced).
  • defaultQuery starts the field with text it then owns: verified (tests "shows defaultQuery without opening the listbox", "lets an uncontrolled field type after defaultQuery").
  • Omitting both keeps today's behaviour: verified (the four named suites pass, 471 tests).
  • A value set from outside does not move focus, open the list or announce a count unless the field has focus: verified (test "does not move focus or open the listbox when the app sets the query while idle"; browser check).
  • A focused clear closes the listbox: true without hasEntriesOnFocus (test "closes the listbox when the app clears the query while the field is focused"); false with it, where the focus entries show.
  • A search the app starts while the field is idle keeps its answer for the next open: verified (browser check: focusing opens it and announces "1 result").
  • value / onChange and theming are unchanged: verified (the API generator lists only the six added props).
  • The pair follows isOpen / defaultIsOpen: verified (Collapsible.tsx:247).
  • 469 tests pass in the four named files: outdated; 471 pass at this head, with the two new tests.
  • The unused composeEventHandlers import in Typeahead.tsx is unchanged: verified (Typeahead.tsx:66, on base and head).
  • Changeset: query and defaultQuery let an app set, clear, restore or keep the typed text: verified.
  • Changeset: onChangeQuery keeps reporting every change, its own included: verified.
  • Changeset: a change from outside does not move focus, open the listbox or announce unless focused: verified.
  • Changeset: a patch bump for a [feat] entry: consistent with the repository's other [feat] changesets.

Files:

  • .changeset/typeahead-and-tokenizer-add-a-controlled-api-to--l7mf.md: clear.
  • packages/core/src/Typeahead/BaseTypeahead.tsx: clear (echo fix, render writes and Effect note verified).
  • packages/core/src/Typeahead/Typeahead.doc.mjs, packages/core/src/Typeahead/BaseTypeahead.doc.mjs: finding (focused-clear wording).
  • packages/core/src/Tokenizer/Tokenizer.doc.mjs: finding (focused-clear wording); note ("entering edit mode").
  • packages/core/src/Tokenizer/Tokenizer.tsx: note ("entering edit mode" in the JSDoc).
  • packages/core/src/Tokenizer/TokenizerBottomSheet.tsx: clear.
  • packages/core/src/Typeahead/Typeahead.tsx: clear.
  • packages/core/src/Typeahead/BaseTypeahead.test.tsx: clear.
  • packages/core/src/Tokenizer/Tokenizer.test.tsx: note (covers the echo with hasEntriesOnFocus only).

Automated review (maintainer link)

With hasEntriesOnFocus a focused clear shows the focus entries rather
than closing the listbox, so the query prop description now says so in
Typeahead, BaseTypeahead and Tokenizer, English and Chinese.
Tokenizer has no edit mode (that is Typeahead's selected value), so the
query and onChangeQuery docs in Tokenizer.tsx and Tokenizer.doc.mjs
(English, Chinese and dense) now name only a pick and a clear.

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

Approval waits on an engineering owner's decision about the new public API, and one description fix and one size report are also needed; the docs fixes asked for in the last review are in.

No current spec covers the controlled query / defaultQuery pair: the BaseTypeahead spec says the query text is internal and that a pick clears it. An engineering owner needs to decide whether to admit the pair, and how a held query after a pick, a value set while the field is idle, a focused clear and the Tokenizer sheet's close should behave; they record it by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner) or by updating the records.

Blocking findings:

  • The description still says a focused clear closes the listbox (Problem and solution fit, Public delta and Evidence), but with hasEntriesOnFocus it shows the focus entries (BaseTypeahead.tsx:1659-1661), so please reword those sentences the way the docs now read and update the "469 tests passed" count, since 471 pass on this head.
  • Newly live check: the description does not report the first-load gzip delta that the component import-boundaries rule asks for when an optional feature is added and a shared module grows, so please state it per page, base against head (our build measured about +243 B on a page with Typeahead, +249 B with Tokenizer, and no change on the four reference pages).

Two smaller points: BaseTypeahead's docs still list "entering edit mode" among the onChangeQuery reports although only Typeahead has an edit mode, and a test with default props that echoes the pick and asserts the "Added …" announcement would lock in the echo fix.

Claims and files checked

Claims:

  • Typeahead, Tokenizer and BaseTypeahead take query and defaultQuery: verified (API surface, tests).
  • Passing query shows that text, and onChangeQuery keeps reporting every change: verified (BaseTypeahead.tsx:1637-1639, :1832-1834, tests).
  • Holding query after a pick keeps the text, and following '' empties it: verified (tests, probe).
  • defaultQuery starts with text the field then owns, without opening the listbox: verified (tests).
  • Omitting both keeps today's behaviour: verified (471 tests pass).
  • A change from outside moves no focus and opens or announces nothing unless the field has focus: verified (Chromium).
  • A focused clear closes the listbox: false with hasEntriesOnFocus.
  • A search started while the field is idle keeps its answer for the next open: verified (Chromium, async probe).
  • 469 tests pass: outdated, 471 pass.
  • No theming attributes change, and value / onChange are unchanged: verified.
  • The unused composeEventHandlers import warning is unchanged: verified.

Files:

  • The changeset: clear.
  • Tokenizer.doc.mjs: clear.
  • Tokenizer.test.tsx: clear.
  • Tokenizer.tsx: clear.
  • TokenizerBottomSheet.tsx: clear.
  • BaseTypeahead.doc.mjs: lists edit mode (non-blocking).
  • BaseTypeahead.test.tsx: clear.
  • BaseTypeahead.tsx: JSDoc lists edit mode (non-blocking).
  • Typeahead.doc.mjs: clear.
  • Typeahead.tsx: clear.

Automated review (maintainer link)

BaseTypeahead has no edit mode, so its query and onChangeQuery docs list
only a pick and a clear. Add a Tokenizer test with default props that
echoes the pick's empty query and asserts the Added announcement.
@mvanhorn

Copy link
Copy Markdown
Author

Thanks. Pushed 2595802 and updated the description.

  • The description now says a focused clear does what emptying the field does: the listbox closes, or shows the focus entries with hasEntriesOnFocus. The test count is 472 with the new test below.
  • Added a First-load size section, base against head. Typeahead +235 B, Tokenizer +257 B, BaseTypeahead +208 B gzip. Text, Heading, Button, IconButton, Link and Table are unchanged. My local numbers are a few bytes off yours, which fits the platform note in the boundaries record.
  • BaseTypeahead's docs and JSDoc no longer list entering edit mode. Typeahead's docs keep it, since Typeahead has one.
  • Added a Tokenizer test with default props that echoes the pick's empty query and checks the "Added Alice" announcement.

The query / defaultQuery spec call is still with an engineering owner.

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

Approval waits on an engineering owner's decision about the new public API, and one docs fix is needed after it; the fixes asked for in the last review are in.

No current spec covers the controlled query / defaultQuery pair: the BaseTypeahead spec says the query text is internal and that a pick clears it. An engineering owner needs to decide whether to admit the pair, and how a held query after a pick, a value set while the field is idle, a focused clear and the Tokenizer sheet's close should behave; they record it by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner) or by updating the records.

Blocking findings:

  • Miss: the dense docs for query (BaseTypeahead.doc.mjs:547, Tokenizer.doc.mjs:926) say a value set from outside never opens the listbox, but a set while the field has focus opens it, as the focused-set test at BaseTypeahead.test.tsx:371-394 shows, so please reword them to "Setting it from outside does not move focus. While the field is unfocused, it does not open the listbox or announce a result count."

CI has not run on this head yet: a maintainer adds the ci:run label so it runs.

Claims and files checked

Claims:

  • Typeahead, Tokenizer and BaseTypeahead take query and defaultQuery: verified (generated API delta, tests).
  • Passing query shows that text, and onChangeQuery keeps reporting every change, the field's own included: verified (BaseTypeahead.tsx:1637-1639, :1832-1834, tests).
  • Holding query after a pick keeps the text, and following the reported empty query empties it: verified (BaseTypeahead.test.tsx:396, Tokenizer.test.tsx:2789, Chromium).
  • defaultQuery starts the field with text it then owns, without opening the listbox: verified (BaseTypeahead.test.tsx:212, :478).
  • Omitting both keeps today's behaviour: verified (472 tests pass).
  • A change from outside moves no focus and opens or announces nothing unless the field has focus: verified (BaseTypeahead.test.tsx:344, Chromium).
  • A focused clear does what emptying the field does, closing the list or showing the focus entries with hasEntriesOnFocus: verified (BaseTypeahead.tsx:1660, BaseTypeahead.test.tsx:371).
  • A search the app starts while the field is idle keeps its answer for the next open, with the list closed and nothing announced: verified (BaseTypeahead.tsx:1255-1268, Chromium).
  • First-load size grows about +235 B with Typeahead, +257 B with Tokenizer and +208 B with BaseTypeahead, with other pages unchanged: verified within a few bytes (+243 B, +249 B, +206 B, 0 B in our build).
  • 472 tests pass in the four named files: verified.
  • value / onChange are unchanged and no theming attributes change: verified (diff).
  • The unused composeEventHandlers import warning in Typeahead.tsx is unchanged: verified.
  • The changeset's description of the props and of onChangeQuery: verified (same evidence as above).
  • The dense docs say a value set from outside never opens the listbox: false while the field has focus.

Files:

  • The changeset: clear.
  • Tokenizer.doc.mjs: dense query entry (blocking).
  • Tokenizer.test.tsx: clear.
  • Tokenizer.tsx: clear.
  • TokenizerBottomSheet.tsx: clear.
  • BaseTypeahead.doc.mjs: dense query entry (blocking).
  • BaseTypeahead.test.tsx: clear.
  • BaseTypeahead.tsx: two comments restate names (non-blocking).
  • Typeahead.doc.mjs: clear.
  • Typeahead.tsx: clear.

Review mode: full — reason: author-not-engowner

Automated review (maintainer link)

…e focused

The query docs for BaseTypeahead and Tokenizer now say a set while the
field is unfocused does not open the listbox or announce a result count,
which matches the focused-set behavior. Two comments in BaseTypeahead.tsx
drop the sentence that restated the name.

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

Approval waits on an engineering owner's decision about the new public API, and one fix is needed after it; the docs and comment fixes asked for in the last review are in.

No current spec covers the controlled query / defaultQuery pair: the BaseTypeahead spec says the query text is internal and that a pick clears it, and the search-vocabulary spec admits a new search capability only against it. An engineering owner needs to decide whether to admit the pair, and how a held query after a pick, a value set while the field is idle, a focused clear and the Tokenizer sheet's close should behave; they record it by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner) or by updating the records.

Blocking findings:

  • Miss: an app that sets query while the field is unfocused and then moves focus into it within the debounce (150 ms by default) gets a focused field showing its text with the list closed and no result announcement, because the scheduled search keeps its idle flag (BaseTypeahead.tsx:1642-1646) and handleFocus (:1977-1983) does not clear it, so please clear idleSearchRef on focus and add a test that focuses before the debounce elapses and expects the list to open.

CI has not run on this head yet: a maintainer adds the ci:run label so it runs.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Typeahead, Tokenizer and BaseTypeahead take query and defaultQuery: verified (generated API delta, tests).
  • Passing query shows that text, and onChangeQuery keeps reporting every change, the field's own included: verified (BaseTypeahead.tsx:1637-1639, :1832-1834, tests).
  • Holding query after a pick keeps the text, and following the reported empty query empties it: verified (BaseTypeahead.test.tsx:396, Tokenizer.test.tsx:2743, :2789, Chromium).
  • defaultQuery starts the field with text it then owns, without opening the listbox: verified (BaseTypeahead.test.tsx:212, :230, :478).
  • Omitting both keeps today's behaviour: verified (472 tests pass).
  • A change from outside moves no focus and opens or announces nothing unless the field has focus: verified for the focus state at the time of the change (BaseTypeahead.test.tsx:344, Chromium); a focus that arrives during the debounce is not honoured (blocking finding).
  • A focused clear does what emptying the field does, closing the list or showing the focus entries with hasEntriesOnFocus: verified (BaseTypeahead.tsx:1659-1661, BaseTypeahead.test.tsx:371).
  • A search the app starts while the field is idle keeps its answer for the next open, with the list closed and nothing announced: verified (BaseTypeahead.tsx:1255-1268, Chromium), except an open during the debounce (blocking finding).
  • First-load size grows about +235 B with Typeahead, +257 B with Tokenizer and +208 B with BaseTypeahead, with other pages unchanged: verified within a few bytes (+243 B, +249 B, +206 B, and 0 B on Text, Button and Table in our build).
  • 472 tests pass in the four named files: verified.
  • value / onChange are unchanged and no theming attributes change: verified (diff, API delta).
  • The unused composeEventHandlers import warning in Typeahead.tsx is unchanged: verified (Typeahead.tsx:66 at base and head).
  • The dense docs now say an outside set opens nothing only while the field is unfocused: verified (BaseTypeahead.doc.mjs:547, Tokenizer.doc.mjs:926).
  • The changeset's description of the props and of onChangeQuery: verified (same evidence as above).

Files:

  • The changeset: clear.
  • Tokenizer.doc.mjs: clear.
  • Tokenizer.test.tsx: clear.
  • Tokenizer.tsx: clear.
  • TokenizerBottomSheet.tsx: clear.
  • BaseTypeahead.doc.mjs: clear.
  • BaseTypeahead.test.tsx: no test focuses the field during the debounce after an outside set (part of the blocking finding).
  • BaseTypeahead.tsx: focus during the debounce after an outside set (blocking).
  • Typeahead.doc.mjs: clear.
  • Typeahead.tsx: clear.

Automated review (maintainer link)

Focusing the field before the debounce of a query the app set while idle now clears the idle flag, so the search opens the listbox and announces. Adds a test for that timing.

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

Approval waits on an engineering owner's decision about the new public API, and one small description fix is needed after it; the focus fix asked for in the last review is in.

No current spec covers the controlled query / defaultQuery pair: the BaseTypeahead spec says the query text is internal and that a pick clears it, and the search-vocabulary spec admits a new search capability only against it. An engineering owner needs to decide whether to admit the pair, and how a held query after a pick, a value set while the field is idle, a focused clear and the Tokenizer sheet's close should behave; they record it by commenting /approve-spec <full head SHA> on this pull request (the author may do so if they are an engineering owner) or by updating the records.

Blocking findings:

  • The description's Testing section says 472 tests pass in the four named files, but this head runs 473 there (the new focus test), so please update the count.

CI has not run on this head yet: a maintainer adds the ci:run label so it runs.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Typeahead, Tokenizer and BaseTypeahead take query and defaultQuery: verified (generated API delta, tests).
  • Passing query shows that text, and onChangeQuery keeps reporting every change, the field's own included: verified (BaseTypeahead.tsx:1637-1639, :1832-1834, BaseTypeahead.test.tsx:295).
  • Holding query after a pick keeps the text, and following the reported empty query empties it: verified (BaseTypeahead.test.tsx:426, :459, Tokenizer.test.tsx:2743, :2789, Chromium).
  • defaultQuery starts the field with text it then owns, without opening the listbox: verified (BaseTypeahead.test.tsx:212, :230, :508).
  • Omitting both keeps today's behaviour: verified (473 tests pass; the uncontrolled branch keeps its code).
  • A change from outside moves no focus and opens or announces nothing unless the field has focus: verified (BaseTypeahead.test.tsx:344, :371, Chromium), including a focus that lands before the debounced search runs (BaseTypeahead.tsx:1977-1981).
  • A focused clear does what emptying the field does, closing the list or showing the focus entries with hasEntriesOnFocus: verified (BaseTypeahead.tsx:1659-1661, BaseTypeahead.test.tsx:401).
  • A search the app starts while the field is idle keeps its answer for the next open, with the list closed and nothing announced: verified (BaseTypeahead.tsx:1255-1268, Chromium).
  • First-load size grows about +235 B with Typeahead, +257 B with Tokenizer and +208 B with BaseTypeahead, with other pages unchanged: verified within a few bytes (+246 B, +252 B, +211 B, and 0 B on Text, Heading, Button, IconButton, Link and Table in our build).
  • 472 tests pass in the four named files: false; 473 pass at this head (blocking finding).
  • The demo note's 469 passing tests: describes a run on the first revision of this pull request, not this one.
  • value / onChange are unchanged and no theming attributes change: verified (diff, API delta).
  • The unused composeEventHandlers import warning in Typeahead.tsx is unchanged: verified (Typeahead.tsx:66 at base and head).
  • Docs ship in Typeahead.doc.mjs, Tokenizer.doc.mjs and BaseTypeahead.doc.mjs: verified.
  • The changeset's description of the props and of onChangeQuery: verified (same evidence as above).
  • Public text and artifacts carry no internal context: verified.

Files:

  • The changeset: clear.
  • Tokenizer.doc.mjs: clear.
  • Tokenizer.test.tsx: clear.
  • Tokenizer.tsx: clear.
  • TokenizerBottomSheet.tsx: clear.
  • BaseTypeahead.doc.mjs: clear.
  • BaseTypeahead.test.tsx: clear.
  • BaseTypeahead.tsx: clear.
  • Typeahead.doc.mjs: clear.
  • Typeahead.tsx: clear.

Automated review (maintainer link)

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 20, 2026
@cixzhang
cixzhang marked this pull request as draft November 20, 2026 08:00
@cixzhang
cixzhang marked this pull request as ready for review November 20, 2026 08:01
@cixzhang cixzhang removed the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 20, 2026
@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 Dec 3, 2026
@cixzhang

cixzhang commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🤖 (Posted by Cindy's agent.) Hi @mvanhorn, thank you for this! We've just started CI on it, but GitHub can't run it while the branch conflicts with main. Could you merge or rebase onto the current main? CI will start automatically on your push, and it's the last step before a maintainer decides on the new query and defaultQuery props.

Resolve conflicts with the opening query added on main: the uncontrolled
query starts from defaultQuery, then the opening query, and a controlled
query takes precedence over both. The Tokenizer passes query and
defaultQuery inside the OpeningQueryContext wrapper and seeds the sheet
from them.
@mvanhorn

mvanhorn commented Dec 3, 2026

Copy link
Copy Markdown
Author

Thanks @cixzhang. Merged current main into the branch in 8d0a093 and pushed 3f5e523; it now merges cleanly.

The conflicts were in BaseTypeahead and Tokenizer, against upstream's new opening-query context. The two compose like this:

  • A controlled query wins. The field shows the app's text, and the opening query does not override it.
  • Uncontrolled, the field starts from defaultQuery and falls back to the opening query when defaultQuery is unset (defaultQuery ?? openingQuery in BaseTypeahead, query ?? defaultQuery ?? openingQuery for the Tokenizer sheet).
  • With neither, behavior matches main as is.

On 3f5e523 these exited 0:

  • pnpm -F @astryxdesign/core typecheck
  • pnpm exec vitest run --root . packages/core/src/Typeahead/BaseTypeahead.test.tsx packages/core/src/Typeahead/Typeahead.test.tsx packages/core/src/Tokenizer/Tokenizer.test.tsx packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx
  • pnpm exec prettier --check packages/core/src/Tokenizer/Tokenizer.tsx packages/core/src/Typeahead/BaseTypeahead.tsx packages/core/src/Typeahead/BaseTypeahead.test.tsx
  • pnpm -F @astryxdesign/core exec eslint src/Typeahead src/Tokenizer

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 3acc3cb

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Typeahead 100.3 kB (+270 B) · 14.8 kB CSS (0) — ✓ · ✓ · ✓
Tokenizer · Storybook 119.0 kB (+251 B) · 22.4 kB CSS (0) 2,710 (+19) ✓ · ✓ · ✓
BaseTypeahead 88.7 kB (+249 B) · 12.3 kB CSS (0) — ✓ · ✓ · ✓

✓ passed · ✗ needs a fix · Δ changed, for review in the shots below · ↻ needs re-verify · — did not run

2 more components
Component Size LoC Visual · A11y · RTL
PowerSearch 327.4 kB (+203 B) · 27.8 kB CSS (0) — — · — · —
TypeaheadItem 6.7 kB (0) · 3.6 kB CSS (0) — ✓ · ✓ · ✓

Package size: @astryxdesign/core 8.18 MB packed (+5.5 kB); no new dependencies.

API changes: core +6 · ~0 · −0

6 API changes (advisory)
Package Where Signature Usage
+ core . · Components · component BaseTypeahead prop defaultQuery?: string <BaseTypeahead defaultQuery={…} />
+ core . · Components · component BaseTypeahead prop query?: string <BaseTypeahead query={…} />
+ core . · Components · component Tokenizer prop defaultQuery?: string <Tokenizer defaultQuery={…} />
+ core . · Components · component Tokenizer prop query?: string <Tokenizer query={…} />
+ core . · Components · component Typeahead prop defaultQuery?: string <Typeahead defaultQuery={…} />
+ core . · Components · component Typeahead prop query?: string <Typeahead query={…} />

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.

Accessibility: 1 violation(s)

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

Tokenizer - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 2/32 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | View full report

@cixzhang

cixzhang commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🤖 (Posted by Cindy's agent.) Thanks for the rebase and the fixes, @mvanhorn! CI is now running, and one lint step fails: "Check the comment-provenance baseline" reports that the baseline is out of date for the Typeahead and Tokenizer files this pull request touches (main updated that baseline today).

To fix it, run node internal/eslint-plugin-astryx/no-comment-provenance.baseline.mjs (without --check) and look at the diff it makes to no-comment-provenance.baseline.json:

  • If it only removes or lowers entries: commit the updated baseline.
  • If it adds entries: your change has new comments that cite pull requests, issues or review history. Please reword those comments to say what the code does instead, and leave the baseline unchanged.

Thank you!

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

Approval waits on an engineering owner's decision about the new public API, and three fixes are needed whatever that decision is.

The six new props (query and defaultQuery on Typeahead, Tokenizer and BaseTypeahead) and the behaviour they bring have no current spec record: the BaseTypeahead record keeps query text internal and has a pick clear it, and it keeps the text a field opens with package-internal. An engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, or by changing the records (the author may do so if they are an engineering owner), deciding a held query after a pick, an outside value set while the field is idle, a focused clear, a held query across a person's close of Tokenizer's sheet, and defaultQuery asking the source at mount.

  • Found by CI: Lint fails on its comment-provenance check: the two comments that start with INV3: in BaseTypeahead.tsx (lines 1700 and 1760) cite a record, so CI's lint job fails; keep the sentences and drop the INV3: label (an earlier review asked for that wording).
  • Tokenizer's bottom sheet mishandles a controlled query: with query set, a keystroke the app does not take leaves the sheet's list busy with no search running, and a value the app sets while the sheet is open is never marked pending or announced (TokenizerBottomSheet.tsx:715-731 starts both only from typing), so the sheet should follow the shown query value and get a test for each case.
  • Regression: The description's test counts are stale: the four named test files now run 503 tests at this head, not 473 (or 469), after the merge of main.
Claims and files checked

Review mode: full; reason: author-not-engowner

  • Claim: six optional props are added next to onChangeQuery — verified (generated API delta; CI's analysis lists the same six).
  • Claim: a set query shows that text and onChangeQuery reports every change the field makes — verified in the three components' tests.
  • Claim: holding query after a pick keeps the text; following '' empties it — verified (tests; Tokenizer inline reproduced locally).
  • Claim: defaultQuery starts the text and the field then owns it — verified (tests).
  • Claim: omitting both keeps today's behaviour — verified (the four suites pass locally and in CI).
  • Claim: an outside set does not move focus, open the list or announce unless the field has focus — false in Tokenizer's sheet with focus in its search field (finding 2); verified inline and for the idle case.
  • Claim: a focused clear does what emptying does, closing the list or showing focus entries — verified inline (test; reproduced locally with focus entries).
  • Claim: an idle search keeps its answer for the next open with the list closed and nothing announced — verified (reproduced locally and in Chromium).
  • Claim: an uncontrolled pick still empties the field; defaultQuery shows without opening — verified (tests).
  • Claim: no theming attributes change — verified (no theme or attribute rows).
  • Claim: first-load size growth of about +208 to +257 B — reported against an older base; measured locally at +181 to +265 B and in CI at +249 to +270 B, under the 0.3 KB allowance.
  • Claim: 473 (and 469) tests passed in the named files — false at this head (finding 3).
  • Claim: lint and format on touched files, with one pre-existing warning — reported; the warning is unchanged, but CI's lint job fails (finding 1).
  • Changeset: same claims as the description; the focused-announce clause is false for the sheet (finding 2); the changeset check passes.
  • Files: .changeset/…l7mf.md finding 2; Tokenizer.doc.mjs finding 2; Tokenizer.test.tsx clear; Tokenizer.tsx finding 2 (JSDoc); TokenizerBottomSheet.tsx finding 2; BaseTypeahead.doc.mjs clear; BaseTypeahead.test.tsx clear; BaseTypeahead.tsx finding 1; Typeahead.doc.mjs clear; Typeahead.tsx clear.

Automated review (maintainer link)

@cixzhang

cixzhang commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

🤖 (Posted by Cindy's agent.) Thank you for the update, @mvanhorn! Before this goes to a maintainer decision, one implementation change is needed: the new layout effect in BaseTypeahead can mostly become plain render and event logic, which Astryx prefers over effects.

  • When the field is idle, no effect is needed. Use the render-time "previous value" state pattern (as DateInput/NativeDateField.tsx does), and run the search on the next open in handleFocus: if (query !== lastSearchedQuery) handleQueryChange(query). That's how an opening query already waits for the field to open. It lets you drop idleSearchRef, isInputFocusedRef and heldQueryAfterPickRef.
  • Keep a small effect only for an app-set query on a field that is already focused, with a short comment saying why: an app-set query on a focused field must cancel the old search timer and close the old list, and no field event carries it.

The name query is fine (it pairs with the existing onChangeQuery). Whether Typeahead and Tokenizer take these props at all is the open maintainer question, and the record updates follow that answer, so there's nothing for you to do there yet. If you'd rather we make the effect change on your branch with you credited, just say so. Thanks!

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

Approval waits on an engineering owner's decision about the six new query and defaultQuery props, and three fixes are needed whatever that decision is.

No current spec covers a public controlled query on Typeahead, Tokenizer or BaseTypeahead: the BaseTypeahead record says the query text is internal and that a pick clears it. An engineering owner needs to decide whether these props ship and how the held-pick, idle-set, focused-clear, sheet-close and mount-search behaviours work, recording it with a /approve-spec <full head SHA> comment or a record change (the author can do this only as an engineering owner).

  • Tokenizer's bottom sheet mishandles a controlled query: with query set, a keystroke the app does not accept leaves the sheet's list busy with a Loading spinner and no search running, and a value the app sets while the sheet is open is searched with no busy state and never announced (TokenizerBottomSheet.tsx:715-731), so start the pending state and search number from the shown query and add sheet tests for both cases.
  • The new query Effect does idle work that render and focus can do: as the maintainer asked, follow the unfocused case with the render-time previous-value pattern and search on the next open in handleFocus, keeping a small Effect only for a value set while the field is focused (BaseTypeahead.tsx:1760-1775).
  • Regression: The description's test counts are stale: the four named test files run 503 tests at this head, not 473 or 469, so update or drop the count.

The comment-provenance lint failure from the last round is fixed, and CI passes at this head.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Title: a controlled API to set or clear the typed query is added: verified (API delta; controlled-query tests).
  • Six optional props, query and defaultQuery, on Typeahead, Tokenizer and BaseTypeahead: verified (built-surface comparison; CI's API report lists the same six).
  • Passing query shows that text and onChangeQuery reports the field's own changes, a pick and a clear included: verified (typing and pick tests; the clear button routes through the input change).
  • Holding query after a pick keeps the text; following the empty report empties it: verified (held-pick and echo tests in Typeahead and Tokenizer).
  • defaultQuery starts the field with text it then owns: verified (default-query tests).
  • Omitting both keeps today's behaviour, and an uncontrolled pick still empties the field: verified (503 tests in the four suites, run here).
  • An outside change moves no focus and, while the field is unfocused, opens nothing and announces no count: verified (idle test; Chromium capture with instant, debounced and slow sources).
  • A focused clear closes the list, or shows the focus entries with hasEntriesOnFocus: verified (focused-clear test; probe with focus entries, run here).
  • An idle search keeps its answer for the next open and the live region stays quiet: verified (Chromium capture: nothing announced while idle, the count once on focus).
  • value and onChange are unchanged and no theming attribute changes: verified (no theme or attribute rows in the API delta).
  • First-load size table: reported (measured here against this base: Typeahead +265 B, Tokenizer +264 B, BaseTypeahead +181 B; the four reference pages +0 B).
  • Lint and format on touched files, with one pre-existing unused-import warning: reported, and matches the checks run here and CI's lint job.
  • "473 tests passed" and "469 tests passed": false (the four files run 503 tests at this head).
  • Public text carries no internal context: verified (no matches).
  • Scope is Typeahead, Tokenizer and BaseTypeahead: verified (every API row is in scope).
  • Changeset: the same claims as above (set or clear text, restore, keep after a pick, reports, no focus move or idle announcement, defaultQuery start): verified as above.

Files:

  • .changeset/typeahead-and-tokenizer-add-a-controlled-api-to--l7mf.md: clear
  • packages/core/src/Tokenizer/Tokenizer.doc.mjs: clear
  • packages/core/src/Tokenizer/Tokenizer.test.tsx: clear
  • packages/core/src/Tokenizer/Tokenizer.tsx: clear
  • packages/core/src/Tokenizer/TokenizerBottomSheet.tsx: finding (controlled query pending state)
  • packages/core/src/Typeahead/BaseTypeahead.doc.mjs: clear
  • packages/core/src/Typeahead/BaseTypeahead.test.tsx: clear
  • packages/core/src/Typeahead/BaseTypeahead.tsx: finding (idle work in the new Effect)
  • packages/core/src/Typeahead/Typeahead.doc.mjs: clear
  • packages/core/src/Typeahead/Typeahead.tsx: clear

Automated review (maintainer link)


// Synchronize the `query` prop to the search source's timer and
// request, the popover layer, and the live region.
useIsomorphicLayoutEffect(() => {

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.

The unfocused half of this Effect has a better home, as the maintainer suggested: follow the shown text during render with the previous-value pattern (DateInput/NativeDateField.tsx:412-415), and in handleFocus run handleQueryChange(query) when query !== lastSearchedQuery, the way the opening query already waits for the first open. Keep a small Effect only for a value the app sets while the field is focused, with a comment saying why no field event carries it. That drops idleSearchRef, isInputFocusedRef and heldQueryAfterPickRef, and defaultQuery no longer asks the source at mount.

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

Approval waits on an engineering owner's decision about the six new query and defaultQuery props, and four fixes are needed whatever that decision is.

No current spec covers a public controlled query on Typeahead, Tokenizer or BaseTypeahead: the BaseTypeahead record says the query text is internal and that a pick clears it. An engineering owner needs to decide whether these props ship and how the held-pick, idle-set, focused-clear, sheet-close and mount-search behaviours work, recording it with a /approve-spec <full head SHA> comment or a record change (the author can do this only as an engineering owner).

  • A keystroke the app rejects is still searched on the inline field: with query set, typing "5" after "Ap" in a field whose app strips digits searches "Ap5", empties the list and announces "Loading" under the unchanged "Ap" before searching "Ap" again (BaseTypeahead.tsx:1650-1665, reproduced in Chromium), so report the keystroke without searching it and search the shown query when it changes, as the bottom sheet now does, with an inline test for a rejected keystroke.
  • The new query Effect does idle work that render and focus can do: as the maintainer asked, follow the unfocused case with the render-time previous-value pattern and search on the next open in handleFocus, keeping a small Effect only for a value set while the field is focused (BaseTypeahead.tsx:1762-1775).
  • TokenizerBottomSheet.test.tsx is not Prettier-formatted: the new FR20 test at lines 2696-2700 fails CI's lint job, so run pnpm exec prettier --write packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx.
  • Regression: The description's test counts are stale: the four named test files run 505 tests at this head (run locally), not 473 or 469, so update or drop the count.

Non-blocking:

  • One sheet comment runs 36 words in one sentence (TokenizerBottomSheet.tsx:477-479); splitting it into three short sentences keeps the reason.

The bottom sheet's stuck Loading row after a rejected keystroke is fixed, and the new sheet tests cover both cases.

Claims and files checked

Review mode: full; reason: author-not-engowner

Claims:

  • Title: a controlled API to set or clear the typed query is added: verified (API delta; controlled-query tests).
  • Six optional props, query and defaultQuery, on Typeahead, Tokenizer and BaseTypeahead, beside the existing onChangeQuery: verified (built-surface comparison; CI's API report lists the same six).
  • Passing query shows that text, and onChangeQuery keeps reporting the field's own changes (typing, a pick, a clear, the sheet's close): verified (typing, pick and sheet tests).
  • Holding query after a pick keeps the text; following the empty report empties it: verified (held-pick and echo tests in Typeahead and Tokenizer).
  • defaultQuery starts the field with text it then owns: verified (default-query tests).
  • Omitting both keeps today's behaviour, and an uncontrolled pick still empties the field: verified (all 505 tests in the four suites, run here).
  • An outside change moves no focus and, while the field is unfocused, opens nothing and announces no count: verified (idle test; Chromium capture with a delayed source).
  • A focused clear closes the list, or shows the focus entries with hasEntriesOnFocus: verified (focused-clear test; probe with focus entries).
  • An idle search keeps its answer for the next open and the live region stays quiet: verified (Chromium capture: nothing announced while idle, the count once on focus).
  • The controlled pair matches isOpen / defaultIsOpen in other fields: verified (Collapsible has both).
  • value and onChange are unchanged and no theming attribute changes: verified (no theme or attribute rows; themes' built surfaces unchanged).
  • First-load size table and its attribution to BaseTypeahead: reported (measured here against this base: Typeahead +265 B, Tokenizer +263 B, BaseTypeahead +181 B; Text, Heading, Button, IconButton, Link and Table unchanged; Tokenizer's own files add about 80 B beyond BaseTypeahead).
  • Lint and format on touched files, with one pre-existing unused-import warning: reported; the unused import is pre-existing, but Prettier fails on one changed test file (finding).
  • "473 tests passed" and "469 tests passed": false (the four files run 505 tests at this head).
  • Scope is Typeahead, Tokenizer and BaseTypeahead, one capability, with docs and tests: verified (every API row is in scope; no unrelated change).
  • Public text carries no internal context: verified (no matches).
  • Changeset: set or clear the text, restore, clear from another control, keep after a pick, reports, no focus move or unfocused announcement, defaultQuery start: verified as above.

Files:

  • .changeset/typeahead-and-tokenizer-add-a-controlled-api-to--l7mf.md: clear
  • packages/core/src/Tokenizer/Tokenizer.doc.mjs: clear
  • packages/core/src/Tokenizer/Tokenizer.test.tsx: clear
  • packages/core/src/Tokenizer/Tokenizer.tsx: clear
  • packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx: finding (Prettier)
  • packages/core/src/Tokenizer/TokenizerBottomSheet.tsx: non-blocking note (comment length); the controlled pending state now follows the shown query
  • packages/core/src/Typeahead/BaseTypeahead.doc.mjs: clear
  • packages/core/src/Typeahead/BaseTypeahead.test.tsx: clear
  • packages/core/src/Typeahead/BaseTypeahead.tsx: finding (rejected keystroke searched; idle work in the new Effect)
  • packages/core/src/Typeahead/Typeahead.doc.mjs: clear
  • packages/core/src/Typeahead/Typeahead.tsx: clear

Automated review (maintainer link)

droppedQueryRef.current = null;
onChangeQuery?.(newQuery);
if (origin === 'input') {
onChangeQuery?.(newQuery);

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.

With query set, this path still schedules a search for the keystroke before the app answers (lines 1674-1740). When the app keeps the text (it strips a digit, caps the length), the field showing "Ap" searches "Ap5": it goes busy, announces "Loading", the empty answer replaces the rows, and only then is "Ap" searched again and "2 results" announced a second time (reproduced in Chromium and in a unit probe; the source is asked ["Ap", "Ap5", "Ap"]). For a controlled field, report the keystroke without searching it and search the query value the field shows when it changes, as the bottom sheet now does, and add an inline test for a rejected keystroke like the sheet's FR20 one.

Comment on lines +477 to +479
// Pending state and the search number follow the shown query rather than
// the keystroke, so a rejected controlled edit never leaves the list busy
// and a query the app sets while open shows busy feedback and announces.

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.

Non-blocking (INV29): one 36-word sentence. Suggested: "Pending state and the search number follow the shown query, not the keystroke. A rejected controlled edit then leaves the list idle. A value the app sets while the sheet is open shows busy feedback and is announced."

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

Approval waits on an engineering owner's decision about the six new query and defaultQuery props on Typeahead, Tokenizer and BaseTypeahead, and three fixes are needed whatever that decision is.

No current component record admits a public query: BaseTypeahead's record keeps the query text internal and gives the opening text no caller prop, and Tokenizer's record clears the query on every close the person makes, so an engineering owner needs to decide whether these components take the pair and how a controlled pick, an idle app-set value, a focused clear, a held query in Tokenizer's sheet and defaultQuery's search at mount should behave. An engineering owner records that decision by commenting /approve-spec <full head SHA> or by updating the records, and the author may do so if they are an engineering owner.

  • A keystroke the app rejects is still searched on the inline field: with a controlled query that strips a digit, the field showing "Ap" searches "Ap5", goes busy, empties its list and says "Loading" twice before searching "Ap" again (reproduced locally and in a browser check).
  • The new query Effect does idle work that render and focus can do: follow the shown text with the render-time previous-value pattern and search on the next focus, keeping a small Effect only for a value set while the field is focused, as the maintainer asked.
  • The description's test counts are stale: the four test files run 505 tests at this head, not 473 or 469.
  • One sheet comment runs 37 words in one sentence: splitting TokenizerBottomSheet.tsx:477-479 into three short sentences would meet the comment style (non-blocking).
Claims and files checked

Review mode: full; reason: author-not-engowner

  • Title: adds a controlled API to set or clear the typed query: verified (six added props; set and clear tests).
  • Changeset and description: Typeahead and Tokenizer (and BaseTypeahead) take query and defaultQuery so an app can set or clear the text: verified (built API surfaces compared; the set-query test runs on all three).
  • Pass query with onChangeQuery to restore, clear or keep the text after a pick: verified (held-pick tests; Tokenizer echo tests).
  • onChangeQuery keeps reporting every change the field makes, a pick and a clear included: verified (typing, pick, clear and sheet-close paths; the engine has two internal writes, both report).
  • An outside change does not move focus, open the list or announce a count unless the field has focus: verified (idle-set test; browser check: the live region stays empty until focus); in Tokenizer's open sheet focus stays inside the sheet when the count is announced.
  • A focused clear closes the list, or shows the focus entries with hasEntriesOnFocus: verified (focused-clear test; a hasEntriesOnFocus probe lists the three focus entries).
  • Omitting both keeps today's internal text: verified (existing cases in the four suites pass).
  • defaultQuery shows without opening the list, and the field types after it: verified (two tests).
  • A controlled pick reports an empty query and keeps a held text; an uncontrolled pick still empties: verified (tests).
  • An idle search keeps its answer for the next open with the list closed and the live region quiet: verified (browser check: closed and quiet, then the count once on focus).
  • Neither component record names a public query pair: verified against the current records.
  • No theming attributes change: verified (built surfaces: no theme rows).
  • First-load size: Typeahead +235 B, Tokenizer +257 B, BaseTypeahead +208 B, other entries 0 B: reported; measured here +265 B, +263 B, +181 B and 0 B, all under the 0.3 KB limit.
  • 473 tests passed in the four files, 469 at the re-run: false (505 tests run here).
  • Lint and format on touched files, with one pre-existing unused-import warning: verified (CI's lint job passes at this head; ESLint run here shows warnings only, that one included).
  • Scope checklist (one capability, no unrelated changes, docs and tests ship, no internal context): verified (only a test import path and an IME comment ride along; no internal context found).

Files:

  • .changeset/typeahead-and-tokenizer-add-a-controlled-api-to--l7mf.md: clear
  • packages/core/src/Tokenizer/Tokenizer.doc.mjs: clear
  • packages/core/src/Tokenizer/Tokenizer.test.tsx: clear
  • packages/core/src/Tokenizer/Tokenizer.tsx: clear (the held query in the sheet is part of the owner question)
  • packages/core/src/Tokenizer/TokenizerBottomSheet.test.tsx: clear
  • packages/core/src/Tokenizer/TokenizerBottomSheet.tsx: one non-blocking comment note
  • packages/core/src/Typeahead/BaseTypeahead.doc.mjs: clear
  • packages/core/src/Typeahead/BaseTypeahead.test.tsx: clear
  • packages/core/src/Typeahead/BaseTypeahead.tsx: two blocking findings
  • packages/core/src/Typeahead/Typeahead.doc.mjs: clear
  • packages/core/src/Typeahead/Typeahead.tsx: clear

Automated review (maintainer link)

This branch was successfully deployed

1 active deployment
Preview — 3acc3cb1 Deployed Dec 4, 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) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants