Skip to content

fix(Selector, MultiSelector): a light dismiss onto another field leaves focus there - #9018

Merged
cixzhang merged 2 commits into
mainfrom
fix/selector-light-dismiss-focus
Oct 31, 2026
Merged

cixzhang merged 2 commits into
mainfrom
fix/selector-light-dismiss-focus

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

Fixes #8952.

User impact

Someone filling in a form who opens a Selector or MultiSelector, then clicks or taps straight into another field, sees that field but isn't in it: focus jumps back to the Selector's trigger. Their next keystroke goes to the closed Selector, and a letter can silently change its value through type-to-select. Keyboard, mouse and touch users who move between fields this way all hit it.

Problem and solution fit

  • Why does focus jump? The list is a native popover="auto". Pressing another field focuses it and the browser then light-dismisses the list; the shared close handler (useSelectorPresentation) focused the trigger unconditionally.
  • Why does that harm the task? The user's chosen field loses focus, and their typing lands in the wrong control and can change a value they didn't mean to touch.
  • Why does that matter? Focus return exists to stop focus being lost. Here focus wasn't lost, so taking it back overrides the user's own choice.

The fix returns focus only when it would otherwise be lost, the same guard DropdownMenu already applies.

Expected behavior and authority

component:Popover (current) AR4: "Dismissal returns focus to the trigger when focus had entered the closing Popover and would otherwise be lost." Selector and MultiSelector use that disclosure through useSelectorPresentation.

Smallest restoration

  • useSelectorPresentation.ts: on hide, skip the trigger focus (and its focus-return styling) when the active element is another element outside the list. Escape, picking an option, or a press on nothing focusable still return focus to the trigger.
  • No public API, visual or default change. The bottom-sheet path is unchanged; it already hands focus back through BottomSheet.

Evidence

  • Reproduction before the change: "leaves focus on the field a press moved it to" fails on main (focus is on the trigger).
  • Result after the change: it passes; "returns focus to the trigger when the press lands on nothing focusable" passes before and after.
  • Representative unchanged path: the existing Escape, selection, light-dismiss toggle (Selector: the overlay menu covers its own trigger — clicking it commits the option on top instead of closing #5004) and bottom-sheet tests pass; the Selector and MultiSelector suites pass (520 tests; two bottom-sheet tests time out only under full-suite load and pass alone, before and after).
  • Regression test: Selector.test.tsx "Selector light dismiss focus (spec:Popover AR4)".

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm vitest run packages/core/src/Selector packages/core/src/MultiSelector. The light-dismiss order (the press focuses the field, then the popover's toggle fires) is reproduced in the test by focusing the field and dispatching the popover's toggle closed, as the existing #5004 test does.

…es focus there

The shared presentation controller focused the trigger on every hide, taking
focus back from a field the press had already focused. Skip the focus return
when focus has landed on another element outside the list, as DropdownMenu
does; Escape, a choice, or a press on nothing focusable still return focus
(spec:Popover AR4).
@vercel

vercel Bot commented Oct 30, 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 30, 2026 8:02pm UTC

Request Review

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

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

Modified Components

MultiSelector (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Entry File (ESM) 273B 273B 0B
Lines of Code 2680 2681 -
Complexity Very High Very High (344) -

Component Size

Component Import before Import after Delta CSS before CSS after Delta
core/MultiSelector 74.2KB 74.3KB +92B 14.8KB 14.8KB 0B
core/Pagination 86.4KB 86.5KB +78B 15.5KB 15.5KB 0B
core/PowerSearch 168.0KB 168.0KB +67B 20.1KB 20.1KB 0B
core/Selector 78.0KB 78.1KB +58B 15.2KB 15.2KB 0B
core/SelectorOption 15.5KB 15.5KB 0B 5.2KB 5.2KB 0B
richtext/RichTextEditorToolbar N/A 214.1KB 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.4KB 35.4KB 0B

Accessibility Audit

Status: The accessibility audit did not run on this pull request. It runs after merges to main and before each release; pull requests that touch components run it with the ci:heavy-lanes label.


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

@astracat-bot

astracat-bot Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 30, 2026, 9:14 PM 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.

Changes requested: the guard fixes the reported focus jump for Selector and for MultiSelector's built-in trigger, but two things need changing before it lands.

  • With renderTrigger, MultiSelector now also leaves focus on the other field instead of returning it to the caller's control, which AST-055 AR3 requires for every light dismiss; keep the return on that path with a test, or have AR3 amended first.
  • pnpm check:changesets fails on the new Changeset: start its body with [fix] and add your @handle on its own line.

[Automated review]

active !== document.body &&
active !== trigger &&
!popoverContentRef.current?.contains(active);
if (focusLandedElsewhere) {

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 renderTrigger, MultiSelector hands the caller's control to this hook as triggerRef (MultiSelector.tsx:2504), so this early return skips the focus return there too. AST-055 AR3 requires closing by a light dismiss to return focus to the caller's control while it is still in the document: with the list open, focusing another field and then dispatching the toggle now leaves focus on the field, where the base returned it to the control. Keep the unconditional return for a caller-rendered trigger (and cover it with a test), or have AR3 amended first.

'@astryxdesign/core': patch
---

Selector, MultiSelector: pressing another field while the list is open now leaves focus in that field. Before, the list's close handler moved focus back to the Selector's trigger, so the next key went to the closed Selector (a letter could change its value through type-to-select). Escape, picking an option, or a press on nothing focusable still return focus to the trigger.

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.

pnpm check:changesets rejects this entry: the body must start with a category tag ([fix] Selector, MultiSelector: …) and credit a contributor (@handle on its own line). pnpm changeset:new writes both.

@cixzhang
cixzhang marked this pull request as ready for review October 30, 2026 19:38
…on every close

spec:AST-055 AR3 returns focus to a renderTrigger control after any close,
light dismiss included. Keep the unconditional return for that path; fix the
Changeset's category tag and contributor line.

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

Looks good to merge: the guard keeps focus in the field a press moved it to, while Escape, a selection, a press on nothing focusable and every renderTrigger close still return focus as component:Popover AR4 and spec:AST-055 AR3 require. The new Selector test fails without the fix and passes with it, and the renderTrigger test fails if isFocusReturnAlways is removed. CI's only test failure is MultiSelector's bottom-sheet test timing out, a path this change does not touch.

[Automated review]

@cixzhang
cixzhang merged commit 0bdda32 into main Oct 31, 2026
142 of 150 checks passed
@github-actions
github-actions Bot deleted the fix/selector-light-dismiss-focus branch October 31, 2026 06:09

This branch was successfully deployed

1 active deployment
Preview — d6044c19 Deployed Oct 30, 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.

[Bug] Selector, MultiSelector: pressing another field while the list is open sends focus back to the trigger

1 participant