Skip to content

fix(DropdownMenu): a trigger the caller renders gets no focus ring after a pointer pick - #7382

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:menu-trigger-focus-return
Oct 13, 2026
Merged

cixzhang merged 2 commits into
meta:mainfrom
vjeux:menu-trigger-focus-return

Conversation

@vjeux

@vjeux vjeux commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

User impact

A pointer row pick (a mouse click in Chromium, a finger in iOS Safari) from a DropdownMenu whose 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

  • Why it occurs: after a pointer dismissal the menu returns focus with a plain trigger.focus({preventScroll: true}), and the browser matches :focus-visible on that focus. The Button path hides the ring with the focus-return helper's style, which cannot reach a caller's control.
  • Why it harms the task: the ring signals keyboard focus right after a pointer, on every row pick.
  • Why it matters: renderTrigger exists 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

Smallest restoration

  • Dialog's focusForLastInput moves unchanged into the existing utils/focusReturn.ts with an optional FocusOptions argument; Dialog passes none, so its calls are the same.
  • The menu's focus return calls focusForLastInput(trigger, {preventScroll: true}). After pointer input it asks for focusVisible: false, first clearing a ring WebKit already drew; after keyboard input it focuses as before. The Button keeps its style.
  • The render prop's no-op onFocus stays; its stale comment now says why.
  • No API, default or visual change. The bottom-sheet presentation returns focus through BottomSheet, unchanged here.

Evidence

  • Reproduction before the change: the new spec's pointer case fails on a main Storybook in Chromium (:focus-visible true). iOS 26.2 Simulator, real Mobile Safari, CustomTrigger story, a tap on the trigger then on Rename: on main the trigger is focused, :focus-visible, outline: solid 2px (twice, screenshots compared).
  • Result after the change: the spec passes; the same taps leave the trigger focused, not :focus-visible, outline: none (twice).
  • Representative unchanged path: a keyboard pick keeps the ring (unit and spec); Dialog's focus tests pass untouched.
  • Regression test or other mutation-sensitive proof: unit cases for a caller-rendered trigger and the Button (pointer focus option, a ring already drawn cleared first, keyboard focus unchanged); the three pointer cases fail on main. focusForLastInput has 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

  • 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 exec vitest run packages/core/src/DropdownMenu/DropdownMenu.test.tsx packages/core/src/utils/focusReturn.test.ts \
  -t "focus return after a pointer pick|focusForLastInput"
  main's DropdownMenu.tsx: 3 failed, 3 passed · with the change: 10 passed

pnpm exec vitest run packages/core/src/DropdownMenu packages/core/src/Dialog packages/core/src/ContextMenu \
  packages/core/src/Popover packages/core/src/BottomSheet packages/core/src/utils packages/core/src/DateInput \
  packages/core/src/DateTimeInput packages/core/src/docPropLiterals.test.ts packages/core/src/docPropReferences.test.ts
  Test Files  55 passed (55)   Tests  1760 passed (1760)

pnpm storybook:build
pnpm exec playwright test DropdownMenuFocusReturn.a11y.browser.spec.ts Dialog.a11y.browser.spec.ts \
  MenuPress.a11y.chromium.spec.ts --project=chromium
  20 passed   (the config's WebKit project would not launch on my machine)

ASTRYX_STORYBOOK_DIR=<main build> pnpm exec playwright test DropdownMenuFocusReturn.a11y.browser.spec.ts --project=chromium
  main: 1 failed (pointer pick: :focus-visible true), 1 passed · this branch: 2 passed

iOS 26.2 Simulator (iPhone 17 Pro), Mobile Safari, real taps, Storybook builds of main and of this branch:
  tap the CustomTrigger story's trigger, tap "Rename", read the trigger
  main:   focused, :focus-visible true,  outline solid 2px   (2 of 2 runs)
  branch: focused, :focus-visible false, outline none        (2 of 2 runs)

pnpm -F @astryxdesign/core typecheck, pnpm lint:strict, check:knowledge   ✓

…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.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 12, 2026
@astracat-bot

astracat-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 12, 2026, 5:21 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.

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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines +13 to +15
* @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.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook and Sandbox are not both ready on the exact-head Vercel preview.

No new or modified components detected.

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

44 of 448 shot(s) changed.

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Selector Indicator Space Bottom Sheet Narrow End RTL neutral light 754,077
Selector Indicator Space Bottom Sheet Wide Start neutral light 740,188
Chat Full AI Chat probe light 238,081
Chat Full AI Chat probe dark 237,048
Markdown Default probe light 159,625
Markdown Default probe dark 158,986
Collapsible Dividers probe dark 66,445
Collapsible Dividers probe light 66,445
Chat Default neutral dark 33,205
Chat Default neutral light 32,876
Chat Empty State probe light 23,531
Chat Empty State probe dark 22,622
ChatAutoScroll Scroll Behavior Comparison neutral dark 15,378
ChatAutoScroll Scroll Behavior Comparison neutral light 14,107
Chat With Attachments probe light 13,406
Chat With Attachments probe dark 11,232
ProgressBar With Target Mark probe dark 7,895
ProgressBar With Target Mark probe light 7,895
TableRowExpansion Detail Panel neutral dark 5,150
TableRowExpansion Detail Panel neutral light 4,068

and 24 more.


Generated by PR Enrichment workflow | View full report

@vjeux vjeux changed the title fix(DropdownMenu): a trigger the caller renders gets no focus ring after a pointer pick in WebKit fix(DropdownMenu): a trigger the caller renders gets no focus ring after a pointer pick Oct 12, 2026
@vercel

vercel Bot commented Oct 12, 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 12, 2026 5:38pm UTC

Request Review

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

Comment on lines +68 to +71
// 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.

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

cixzhang pushed a commit that referenced this pull request Oct 13, 2026
…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 cixzhang 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.

CodeBunny approved at this head; CI green. Approved.

@cixzhang
cixzhang enabled auto-merge (squash) October 13, 2026 01:36
@cixzhang
cixzhang merged commit d6b9731 into meta:main Oct 13, 2026
50 checks passed
@vjeux
vjeux deleted the menu-trigger-focus-return branch October 13, 2026 01:51

This branch was successfully deployed

1 active deployment
Preview — 6d49a621 Deployed Oct 12, 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.

2 participants