Repository navigation
fix(DropdownMenu): a trigger the caller renders gets no focus ring after a pointer pick - #7382
Conversation
…ter a pointer pick in WebKit
After a pointer dismissal the menu returned focus with a plain
`trigger.focus({preventScroll: true})`, and WebKit matches :focus-visible on
that programmatic focus after a touch. The design system's Button hid the
ring with the focus-return helper's style, which cannot reach a control the
caller renders, so a renderTrigger trigger rang after every touch pick.
Dialog's focusForLastInput (meta#7313) moves unchanged into utils/focusReturn.ts
with an optional FocusOptions argument, and the menu's focus return uses it:
after pointer input it asks the browser for focusVisible: false, clearing a
ring WebKit already drew first; after keyboard input it focuses as before.
The stale comment on the render prop's no-op onFocus now says why none is
needed.
Tests: unit cases for both triggers (three fail on main), focusForLastInput
cases, and a cross-browser spec on the CustomTrigger story.
|
AI review status for this pull request.
|
There was a problem hiding this comment.
This change brings caller-rendered DropdownMenu triggers in line with the last-input focus rule, and no defects turned up: running your new browser spec against main and this branch, the pointer case fails on main and passes here in both Chromium and WebKit, while the keyboard case and Dialog's focus moves are unchanged. Two small wording fixes would make the record accurate:
- The description says CI runs the new spec in WebKit, but no workflow installs WebKit or runs this spec on pull requests, so please reword that line (or wire the spec into a lane if you want CI coverage).
- The changeset and the spec header call the ring WebKit-specific, but on main a mouse pick leaves it in Chromium too, so engine-neutral wording would describe the fix better.
[Automated review]
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] A `DropdownMenu` whose trigger the caller renders (`renderTrigger`) returns focus to it without a focus ring after a pointer pick in WebKit (Safari, iOS), as the built-in trigger already did: the menu now asks the browser not to treat that focus as keyboard focus, the way Dialog's focus moves do. |
There was a problem hiding this comment.
Non-blocking: on main a mouse pick also leaves a caller-rendered trigger matching :focus-visible in Chromium — the new browser spec's pointer case fails there against a Storybook built from main — so "in WebKit (Safari, iOS)" undersells this fix. Consider dropping the engine qualifier.
There was a problem hiding this comment.
Confirmed: the pointer case fails on a main build in Chromium too (:focus-visible true), and passes on this branch. 6d49a62 names both engines in the changeset (a mouse click in Chromium, a click or a tap in WebKit), and the title and description no longer say "in WebKit".
| * @position Cross-browser proof; jsdom only proves which focus call the menu | ||
| * makes. WebKit is the engine that rings the returned focus after a pointer | ||
| * pick when the menu does not ask it not to. |
There was a problem hiding this comment.
Non-blocking: against a Storybook built from main, the pointer case here fails in Chromium as well as WebKit, so "WebKit is the engine that rings the returned focus" is narrower than what happens. Also, no pull-request workflow runs this file and no workflow runs WebKit, so its WebKit half currently runs only locally.
There was a problem hiding this comment.
Reworded in 6d49a62: unless the menu asks for no ring, both engines ring the focus it returns after a pointer pick. On coverage, the description now says no pull-request workflow runs this file. Release checks run its Chromium half, because the config's chromium project also matches *.a11y.browser.spec.ts, and the jsdom routing tests run on every PR. I left CI wiring out to keep this to one fix. The earlier "WebKit runs it in CI" line was corrected in the description before this review landed.
A mouse pick leaves a caller-rendered trigger matching :focus-visible in Chromium too (the new spec's pointer case fails on a main build there), so the changeset, the spec header and two comments name both engines.
PR Analysis Report
No new or modified components detected. Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression44 of 448 shot(s) changed. A change here is a question, not a failure: check whether the after is the
and 24 more. Generated by PR Enrichment workflow | View full report |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
This change brings renderTrigger menus in line with the last-input focus rule, and the evidence holds up: the new browser spec's pointer case fails on main and passes here in both Chromium and WebKit, the keyboard pick and the built-in Button trigger look the same before and after, and Dialog's focus moves are unchanged. Nothing is required before merge. One optional follow-up: after a mouse pick, in both engines, the popover's own focus restoration has already put a ring on the trigger when the menu's hide handler runs, so the blur-then-refocus branch in focusForLastInput is the normal path there (the trigger sees focus, blur, focus), and the helper and test comments that attribute this to WebKit could say "the browser" instead.
[Automated review]
| // Focusing the element that already has focus does nothing, so a ring the | ||
| // browser already drew would stay. WebKit draws one when its own focus | ||
| // restoration (a dialog's close, a popover's hide) moves focus itself, so | ||
| // clear that focus first. |
There was a problem hiding this comment.
Non-blocking: Chromium does this too. With a menu trigger rendered through renderTrigger, both Chromium 149 and WebKit 26.5 have already focused the trigger, matching :focus-visible, through the popover's own focus restoration when handleLayerHide runs after a mouse pick, so this blur runs there and the trigger sees focus, blur, focus. Saying "the browser" rather than "WebKit" here, and in the matching comment in DropdownMenu.test.tsx, would keep this from reading as a WebKit-only branch.
…ring (#7388) When its exit motion ends, the standalone BottomSheet closes its native dialog, which restores focus to the opener, then calls a plain focus() on finalFocusRef or the opener. Nothing consults the last input, so WebKit rings the returned focus after a tap and Chromium carries a keyboard ring over to it after a mouse close. A DropdownMenu bottom-sheet trigger the caller renders shows it, since only built-in triggers hide it with a style. The sheet now turns on the shared modality tracking and returns focus with focusForLastInput: after pointer input it asks for focusVisible: false, clearing a ring the native close already drew; after keyboard input it focuses as before. The helper is Dialog's, moved into utils/focusReturn.ts with the same hunks as #7382, so the two merge in either order. Tests: four unit cases (three fail on main), a cross-browser spec on a new DropdownMenu story (custom trigger, bottom-sheet presentation).
cixzhang
left a comment
There was a problem hiding this comment.
CodeBunny approved at this head; CI green. Approved.
User impact
A pointer row pick (a mouse click in Chromium, a finger in iOS Safari) from a
DropdownMenuwhose trigger the caller renders (renderTrigger) returns focus to that trigger with the focus ring, as if on a keyboard. The built-in Button trigger shows none.Problem and solution fit
trigger.focus({preventScroll: true}), and the browser matches:focus-visibleon that focus. The Button path hides the ring with the focus-return helper's style, which cannot reach a caller's control.renderTriggerexists so any control can open a menu; each rings after every pick.The focus move itself now carries the last input, so it reaches any trigger.
Expected behavior and authority
component:DropdownMenuDEC-1 (decided): a pointer dismissal returns focus to the trigger with the ring suppressed.architecture:interaction-modalityINV1 (current): programmatic focus after pointer input shows no keyboard indicator.Smallest restoration
focusForLastInputmoves unchanged into the existingutils/focusReturn.tswith an optionalFocusOptionsargument; Dialog passes none, so its calls are the same.focusForLastInput(trigger, {preventScroll: true}). After pointer input it asks forfocusVisible: false, first clearing a ring WebKit already drew; after keyboard input it focuses as before. The Button keeps its style.onFocusstays; its stale comment now says why.Evidence
mainStorybook in Chromium (:focus-visibletrue). iOS 26.2 Simulator, real Mobile Safari, CustomTrigger story, a tap on the trigger then on Rename: onmainthe trigger is focused,:focus-visible,outline: solid 2px(twice, screenshots compared).:focus-visible,outline: none(twice).main.focusForLastInputhas its own cases. The new cross-browser spec covers both picks; no pull-request workflow runs it, release checks run its Chromium half, and WebKit would not launch here.Scope
Testing