Repository navigation
fix(Selector, MultiSelector): a light dismiss onto another field leaves focus there - #9018
Conversation
…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).
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook Preview🧪 Sandbox PreviewModified ComponentsMultiSelector (@astryxdesign/core) · View in Storybook
Component Size
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 SummaryGzip figures measure each package's entry file, not the code an import pulls in.
Accessibility AuditStatus: The accessibility audit did not run on this pull request. It runs after merges to Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
AI review status for this pull request.
|
There was a problem hiding this comment.
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:changesetsfails on the new Changeset: start its body with[fix]and add your@handleon its own line.
[Automated review]
| active !== document.body && | ||
| active !== trigger && | ||
| !popoverContentRef.current?.contains(active); | ||
| if (focusLandedElsewhere) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
…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.
There was a problem hiding this comment.
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]
Fixes #8952.
User impact
Someone filling in a form who opens a
SelectororMultiSelector, 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
popover="auto". Pressing another field focuses it and the browser then light-dismisses the list; the shared close handler (useSelectorPresentation) focused the trigger unconditionally.The fix returns focus only when it would otherwise be lost, the same guard
DropdownMenualready 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 throughuseSelectorPresentation.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.Evidence
Selector.test.tsx"Selector light dismiss focus (spec:Popover AR4)".Scope
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'stoggleclosed, as the existing #5004 test does.