Skip to content

fix(DropdownMenu): return focus to the trigger after a pointer dismissal, without a ring - #6825

Merged
cixzhang merged 2 commits into
meta:mainfrom
vjeux:menu-close-focus
Oct 3, 2026
Merged

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

Conversation

@vjeux

@vjeux vjeux commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

User impact

Anyone who picks a DropdownMenu row with a mouse or finger, or presses outside the menu on nothing focusable. The menu closes and focus lands on the page body: handleLayerHide blurs the trigger after every pointer dismissal. A keyboard user who then reaches for the arrows has lost their place; a screen-reader user hears nothing after the pick. Restoring focus to the trigger keeps the person where they were.

Problem and solution fit

Why it occurs: the blur was added so Safari would not paint a focus ring on the trigger after a touch pick. Why it harms: dropping focus to the body makes the next keyboard step start from nowhere and silences assistive technology. Why it matters: the bottom-sheet presentation of the same component already solved this the right way — return focus and suppress the ring after pointer input — so the two presentations disagree. The fix makes the pointer menu do what the sheet does.

Expected behavior and authority

architecture:interaction-modality INV1: a returned focus after pointer input does not show the keyboard indicator. The DropdownMenu record is a draft and does not yet state focus return; this PR adds FR9 and component:DropdownMenu/DEC-3 (pointer dismissal returns focus to the trigger, ring suppressed). The one owner decision needed is that DEC-3. A draft is not approval.

Smallest restoration

handleLayerHide returns focus to the trigger through the existing useFocusReturnVisibility helper instead of blurring it, unless a press outside already moved focus to a focusable control, which keeps it. No API, type, default, visual or theming change. One existing test is rewritten to the corrected contract: "does not leave focus on the trigger after pointer dismissal" → "returns focus to the trigger after pointer dismissal without a focus ring".

Evidence

  • Reproduction before the change: pointer pick or press outside → trigger blurred, document.activeElement is the body.
  • Result after the change: focus on the trigger with the suppressed-ring class; keyboard dismissal keeps its ring.
  • Representative unchanged path: "restores focus to the trigger after keyboard dismissal", controlled open/close, bottom-sheet presentation, Escape and Tab cases.
  • Regression tests: "returns focus to the trigger after pointer dismissal without a focus ring", "leaves focus on the control a press outside landed on", "returns focus to the trigger after a pointer pick without a ring".

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 lint
pnpm vitest run packages/core/src/DropdownMenu packages/core/src/ContextMenu

pnpm check:repo passes; eslint on the touched files: 0 errors.

 Test Files  1 failed | 3 passed (4)
      Tests  2 failed | 186 passed (188)

The 2 failures are ContextMenu.test.tsx bottom-sheet cases that fail identically on a bare main checkout in this environment; every DropdownMenu case passes.

…sal, without a ring

DropdownMenu blurred its trigger after a pointer pick or an outside press,
so focus fell to the page and the next arrow key went nowhere. Focus now
returns to the trigger with the ring suppressed after pointer input, through
the shared focus-return visibility helper the bottom-sheet presentation
already used, and stays visible after a keyboard pick. A press outside that
landed on a focusable control keeps focus there.
@vercel

vercel Bot commented Oct 1, 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 3, 2026 12:29am UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Oct 3, 2026, 12:34 AM UTC

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

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

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

15 of 420 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
Chat Full AI Chat probe light 155,733
Chat Full AI Chat probe dark 155,005
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,229
Chat With Attachments probe dark 11,065
SideNav Resizable in AppShell probe dark 3,208
Markdown Default probe dark 897
Markdown Default probe light 897
Markdown Default neutral dark 882
Markdown Default neutral light 858

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

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

Thanks for the careful fix — returning focus to the trigger after a pointer dismissal, with the ring suppressed for pointer use and kept for keyboard use, reads clearly and the added tests cover the pick, outside-press, and landed-on-a-control cases well.

Approval needs one maintainer decision first. Today the shared interaction record settles only whether a returned focus shows its ring; the DropdownMenu record itself is still a draft and does not yet state where focus goes when the pointer menu closes, and this change proposes that rule as a still-pending decision. A maintainer needs to provide or identify the governing spec claim that settles this focus destination — returning focus to the trigger on pointer-menu close, with focus left on a control an outside press landed on — or update that claim so the proposed rule becomes current. Nothing needs to be removed or split for this reason, and no code defect was found; once that destination is settled, the implementation evidence here can carry the approval.

[Automated review]

Resolves against the landed shared press model (meta#6681):
- DropdownMenu.tsx: keep both declarations; the hide path cancels the press
  gesture first, then runs focus return.
- DropdownMenu.test.tsx: keep the press-model suite and the focus-return
  suite as separate blocks.
- DropdownMenu.spec.md: keep the module's FR5, renumber this PR's focus-return
  invariant FR9 -> FR6 (the stack's FR6-FR8 are not on main), and number its
  decision DEC-1 (main carries no component-local decision).

108 DropdownMenu tests pass; check:knowledge aligned.

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

Thanks for the careful fix — returning focus to the trigger after a pointer dismissal, with the ring suppressed for pointer use and kept for keyboard use, reads clearly and the added tests cover the pick, outside-press, and landed-on-a-control cases well.

Approval needs one maintainer decision first. Today the shared interaction record settles only whether a returned focus shows its ring; the DropdownMenu record itself is still a draft and does not yet state where focus goes when the pointer menu closes, and this change proposes that rule as a still-pending decision. A maintainer needs to provide or identify the governing spec claim that settles this focus destination — returning focus to the trigger on pointer-menu close, with focus left on a control an outside press landed on — or update that claim so the proposed rule becomes current. Nothing needs to be removed or split for this reason, and no code defect was found; once that destination is settled, the implementation evidence here can carry the approval.

[Automated 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.

All four focus destinations are right, nested flyouts included. Nit: add a not-suppressed assertion to the keyboard-dismissal test — deleting the trigger's new onFocus corrector currently leaves the suite green.

[Automated review]

@cixzhang
cixzhang enabled auto-merge (squash) October 3, 2026 00:36
@cixzhang
cixzhang merged commit 2b5efc9 into meta:main Oct 3, 2026
42 checks passed
cixzhang added a commit that referenced this pull request Oct 3, 2026
…6901)

#6825 made a pointer dismissal return focus to the trigger with the ring
suppressed. The suppression belongs to that pointer, not to the trigger, so a
keyboard user who tabs away and back must get the ring again — the trigger's
own onFocus clears the suppression once the modality is keyboard.

No test covered that second half: deleting the onFocusReturnTargetFocus call
left all 108 DropdownMenu tests green. This adds the assertion. Verified as a
real guard by removing both call sites, which fails exactly this case.

Test-only; no runtime change and no changeset.
cixzhang added a commit to vjeux/astryx that referenced this pull request Oct 3, 2026
Both sides appended to DropdownMenu's invariant table, verification map and
test file. Main's FR6 (focus return after a pointer dismissal, from meta#6825)
and its DEC-1 are kept as they landed; this branch's menuMaxHeight invariant
is renumbered FR10 -> FR7 and its decision DEC-3 -> DEC-2, since main's
DEC-1 now holds that number. Both test suites are preserved in full.
cixzhang added a commit to vjeux/astryx that referenced this pull request Oct 3, 2026
Both sides appended to DropdownMenu's invariant table, verification map,
decision log and test file. Main's focus-return work (meta#6825) keeps FR6 and
DEC-1; this branch's press model becomes FR7 and the trigger render prop
FR8, with its decision renumbered to DEC-2. The trigger Button now carries
both the press handlers from the stacked change and main's focus-return
props. Both test suites are preserved.
cixzhang added a commit to vjeux/astryx that referenced this pull request Oct 3, 2026
Main's focus-return work (meta#6825) keeps FR6 and DEC-1; this branch's press
model invariant becomes FR7. The trigger Button carries both sides: the
press handlers and composed click capture from here, and main's suppressed
focus ring and onFocus return.
@vjeux
vjeux deleted the menu-close-focus branch October 3, 2026 08:31
cixzhang added a commit to vjeux/astryx that referenced this pull request Oct 3, 2026
Main's focus-return work (meta#6825) keeps FR6 and DEC-1; the triangle invariant
becomes FR7 and its decision DEC-2. Both test suites are preserved, and the
hover hook's imports are combined.

This branch was successfully deployed

1 active deployment
Preview — 2ed317e1 Deployed Oct 3, 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