Skip to content

fix(Selector, MultiSelector): a query change clears the highlight from the previous list - #8871

Merged
cixzhang merged 8 commits into
mainfrom
fix/selector-search-highlight-first
Nov 9, 2026
Merged

cixzhang merged 8 commits into
mainfrom
fix/selector-search-highlight-first

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #8833. Builds on #8868 (merged; the opening highlight, component:Selector FR8).

User impact

In a searchable Selector or MultiSelector, a keyboard user who arrows down a few rows and then types a filter got a highlight left over from the old list. It named a different option of the filtered list, or one past its end, so Enter picked an option they never moved to, or nothing while no option looked highlighted.

  • Selector and MultiSelector: typing clears the highlight, so Enter never picks an option the user didn't highlight; with nothing highlighted, Enter selects nothing. ArrowDown then starts at the first row: the first enabled match in Selector, and Select all or the create row when shown in MultiSelector.

Problem and solution fit

  • Cause: the highlight is an index into the filtered list, held in state that survives query changes.
  • Fix: when the query changes, the highlight is cleared during render (no effect), in both components.
  • Why clear rather than highlight the first match: highlighting the first match on every query change is automatic selection, which component:Selector FR8 doesn't allow for a search list opened by typing. In MultiSelector, a highlighted row would also take Left and Right into its action cell (component:MultiSelector FR10), and Enter with nothing highlighted creates the typed label (FR9).

Current specification

  • component:Selector: the searching state is "Visible options, keyboard navigation, and announced result count use one filter". APG combobox: aria-activedescendant must reference a rendered element. New FR9: "In a search list, each change to the query clears the highlight, so aria-activedescendant never names an option of the previous list; ArrowDown then starts at the first enabled option, and Enter with nothing highlighted selects nothing."
  • component:MultiSelector: new FR16 records the clearing rule and how it relates to FR9 and FR10, with its verification row.
  • Authority: the specs owner ruled both rows consistent with the APG combobox pattern and the components' FR8, FR9 and FR10.

Evidence

  • Selector.searchHighlight.test.tsx, 5 cases. 3 fail on main:
    • Selector: ArrowDown twice (Apricot), then b. main keeps index 1 and highlights Blueberry, which Enter picks; here nothing is highlighted, Enter selects nothing, and ArrowDown lands on Banana.
    • Selector: ArrowDown to Cherry, then ap. main keeps an index past the two-row list; here nothing is highlighted, and ArrowDown lands on Apple.
    • MultiSelector: ArrowDown twice, then b. main ticks Blueberry on Enter; here Enter ticks nothing, and ArrowDown starts at Banana.
  • The other 2 guard paths: a list reopened after a search highlights nothing (FR8), and ArrowDown highlights nothing when the only match is disabled.
  • Selector and MultiSelector suites pass (17 files, 585 tests); check:knowledge and the comment-provenance baseline pass.

Writing rubric results

  • R1 narration: none; both rows state what the list does.
  • R2 research: none.
  • R3 evidence: bases name the APG pattern and the tests.
  • R4 rejected alternatives: none in the records; the choice to clear is explained here.
  • R5 change references: none.
  • R6 open questions: none.

…light from the previous list

With hasSearch, the highlight was an index into the filtered list that
survived query changes: after arrowing and typing it named another option,
or one past the end, so aria-activedescendant pointed at nothing rendered
and Enter picked an option the user never moved to, or nothing.

Selector (component:Selector FR9): each query change highlights the first
enabled match of the new list, as the library's Typeahead does. MultiSelector
(component:MultiSelector FR11): each query change clears the highlight,
because with a row highlighted Left and Right move into a row's action cell
instead of the caret (FR10), and Enter with nothing highlighted creates
(FR9); ArrowDown then starts at the first match. Both adjust during render
as the query changes.

Selector.searchHighlight.test.tsx; the Selector cases fail on main.
Stacked on #8868 (opening highlight, FR8).
@vercel

vercel Bot commented Oct 28, 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 Nov 9, 2026 1:37am UTC

Request Review

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

astracat-bot Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 9, 2026, 1:48 AM UTC

@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 fix needs an owner decision before it can be approved: component:Selector FR9 (highlight the first enabled match after each query change) and FR11 in the draft component:MultiSelector record (clear the highlight) are new rules that the current specs do not state, so an engineering owner records the decision by commenting /approve-spec <full head SHA> on this pull request, which the author may do as an engineering owner, or names a different rule. Separately, one regression and a few record details need fixing:

  • Closing a searchable Selector after typing leaves the first option highlighted, so a list reopened by a click or Enter starts on it and Enter replaces the value, against FR8 (Selector.tsx:1364-1368 runs on the query reset at :1151); resetting the highlight from the typing handlers and adding a reopen test would fix it.
  • FR11 and the changeset say ArrowDown starts at the first match, but with hasSelectAll or hasCreate it lands on Select all or the create row first.
  • Two of FR9's four listed cases (the disabled-only match and the shrinking list) already pass without the fix; arrowing down to Cherry and then typing ap reproduces the stale index.
  • The MultiSelector comment and test cite component:Selector FR9 for the clearing rule instead of component:MultiSelector FR11, and FR11's table row is missing its review-state cell.

[Automated review]

Comment thread packages/core/src/Selector/Selector.tsx Resolved
Comment thread .changeset/selector-search-highlight.md Resolved
@cixzhang
cixzhang marked this pull request as draft October 30, 2026 21:06
…earch list highlights nothing

CodeBunny: closing a searchable Selector reset the query, and the FR9
render-time adjust then highlighted the first option, so a list reopened by
a press or Enter started on it and Enter replaced the value, against FR8.
The adjust now highlights the first enabled match only while the list is
open; a reset while closed clears the highlight.

Also: MultiSelector FR11 and the changeset say ArrowDown starts at Select
all or the create row when shown; the MultiSelector comment and test cite
MultiSelector FR11; FR11's table row gets its review-state cell; FR9's
verification row names the failing-before case (ArrowDown to Cherry, then
'ap'), now a test, and the reopen case.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 9cb22b3

@cixzhang

Copy link
Copy Markdown
Contributor Author

Posted by Cindy's agent on her behalf: the approval above covers this PR's own Selector FR9 consistency edit. It follows current Selector AR3 and the Typeahead first-match precedent: each query change highlights the first enabled filtered option. The FR8 opening-highlight row comes from the base PR and needs that PR's own approval.

@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 Selector FR9 and MultiSelector FR11 highlight rules carry an engineering owner's approval for this exact head, the reopen issue from the earlier revision is fixed, and the new tests fail before the change and pass after it. It should land after #8868, whose FR8 opening rule needs that pull request's own approval, and then be retargeted to main. One optional cleanup: the test named "skips a disabled first match" only covers a disabled-only match, so nothing yet guards moving past a disabled first match to the next enabled one.

[Automated review]

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 8, 2026
@cixzhang
cixzhang changed the base branch from lane4/selector-closed-arrow-open-selected to main November 9, 2026 00:20
# Conflicts:
#	.changeset/selector-opens-on-selected.md
#	docs/specs/components/Selector/Selector.spec.md
#	packages/core/src/MultiSelector/MultiSelector.spec.md
#	packages/core/src/MultiSelector/MultiSelector.tsx
#	packages/core/src/MultiSelector/hooks.ts
#	packages/core/src/Selector/Selector.openHighlight.test.tsx
#	packages/core/src/Selector/Selector.tsx
#	packages/core/src/Selector/hooks.ts
… and match main's trigger name

MultiSelector reads searchQuery and setHighlightedIndex, so its reset
sits after the combobox hook. A searchable Selector's trigger name now
carries the selected value, so the tests match its leading label.
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 0dda469

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Selector 99.8 kB (+22 B) · 17.4 kB CSS (0) — ✗ · ✓ · ✓
SelectorOption 20.9 kB (0) · 6.1 kB CSS (0) — ✗ · ✓ · ✓
MultiSelector · Storybook 94.9 kB (+48 B) · 16.8 kB CSS (0) 2,701 (+6) ✓ · ✓ · ✓
3 more components
Component Size LoC Visual · A11y · RTL
Pagination 109.9 kB (+29 B) · 17.8 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 278.0 kB (+22 B) · 454 B CSS (0) — — · — · —
PowerSearch 286.6 kB (+21 B) · 24.1 kB CSS (0) — — · — · —
Visual changes: 4 snapshots in 1 component

A change is a question for the reviewer, not a failure.

Component · story Before After Diff
Selector · Indicator Space Bottom Sheet Wide Start (neutral, dark) before frame after frame diff frame
Selector · Indicator Space Bottom Sheet Wide Start (neutral, light) before frame after frame diff frame
Selector · Indicator Space Bottom Sheet Narrow End RTL (neutral, dark) before frame after frame diff frame
Selector · Indicator Space Bottom Sheet Narrow End RTL (neutral, light) before frame after frame diff frame

Package size: @astryxdesign/core 7.19 MB packed (+591 B); no new dependencies.

API changes: none in this pull request

Committed API report behind this build: cli 29 rows, core 34 rows, theme-butter 1 row, theme-y2k 1 row; run pnpm api:report.

Touched components checked; add ci:run-visual or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

…s does

Highlighting the first match on every query change would be automatic
selection, which FR8 does not allow for a search list opened by typing.
Selector now clears the highlight like MultiSelector: ArrowDown starts
at the first enabled match, and Enter with nothing highlighted does
what it did before. FR9, its verification row and the changeset say
so.
@cixzhang cixzhang changed the title fix(Selector, MultiSelector): a query change no longer keeps the highlight from the previous list fix(Selector, MultiSelector): a query change clears the highlight from the previous list Nov 9, 2026
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 0d359f4

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 9, 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 requested: the fix itself behaves as the new component:Selector FR9 and component:MultiSelector FR16 describe, but the description and two tests still need to catch up with the switch to clearing the highlight.

  • The description's User impact lists "typing with nothing highlighted left Enter doing nothing" as a problem this change keeps by design, and its Evidence section describes first-match tests that no longer exist (Apple highlighted after ap, Enter picking Cherry, a changed grouped-filter case, every Selector case failing on main), so please rewrite both to match this head.
  • Both "clears a highlight left from before the query" cases arrow to index 3 before typing b, so the old index is already past the two-row list and the Selector case passes on main; press ArrowDown twice (Apricot) before b and assert that aria-activedescendant is null, so a highlight kept inside the list (Blueberry, which main picks on Enter) fails as the FR9 and FR16 verification rows say.

Smaller, non-blocking: the MultiSelector comment still says Selector moves to the first match, the Selector comment could keep only its reason, the avo case name promises a disabled-skip case it does not cover, and FR9's "does what it does today" could state the behavior.

[Automated review]

@cixzhang
cixzhang marked this pull request as ready for review November 9, 2026 01:01
@cixzhang
cixzhang marked this pull request as draft November 9, 2026 01:24
…ide the new list

Arrowing to Apricot before typing b leaves an index inside the two-row
list, so main highlights Blueberry and these cases fail there. FR9
states that Enter with nothing highlighted selects nothing, and two
comments keep only their reasons.
@cixzhang

cixzhang commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

/approve-spec 0dda469

@github-actions github-actions Bot added needs:spec-owner-review Current knowledge records await owner approval and removed needs:spec-owner-review Current knowledge records await owner approval labels Nov 9, 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.

Approved pending CI: CI has not run on this head yet, because the pull request is still a draft; marking it ready for review starts the run.

Typing in a searchable Selector or MultiSelector now clears the highlight left from the previous list, as the newly approved component:Selector FR9 and component:MultiSelector FR16 describe. The in-list and past-the-end cases fail on main and pass here, and the earlier requests on the description and the tests are addressed.

Non-blocking: the two new source comments could drop "Adjusted during render rather than in an effect." (and MultiSelector's "so it is cleared"), which restate the code below them; suggestions are inline.

[Automated review]

Comment on lines +1606 to +1608
// A new query is a new list: the old highlight's index would name another
// option, or one past the end. Adjusted during render rather than in an
// effect.

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): "Adjusted during render rather than in an effect." restates where the code below runs and gives no reason. Suggested: A new query is a new list. The old index would name another option, or one past the end.

Comment on lines +1883 to +1886
// A new query is a new list: the old highlight's index would name another
// row, or one past the end, so it is cleared. With no row highlighted, Left
// and Right stay the search field's caret keys. Adjusted during render
// rather than in an effect.

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): "so it is cleared" restates setHighlightedIndex(-1) in the passive, and "Adjusted during render rather than in an effect." restates where the code runs. Suggested: A new query is a new list. The old index would name another row, or one past the end. With no row highlighted, Left and Right stay the search field's caret keys.

@cixzhang
cixzhang marked this pull request as ready for review November 9, 2026 02:11
github-actions Bot added a commit that referenced this pull request Nov 9, 2026
@cixzhang
cixzhang merged commit dd61bd5 into main Nov 9, 2026
130 checks passed
@github-actions
github-actions Bot deleted the fix/selector-search-highlight-first branch November 9, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — 0dda4695 Deployed Nov 9, 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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Selector, MultiSelector: typing in the search field leaves the highlight index from the previous list

1 participant