Skip to content

test(core): the focus-return reveal spec closes a menu only after the keyboard open moved focus in - #14301

Merged
cixzhang merged 1 commit into
mainfrom
lane2/focus-return-reveal-wait-open
Dec 4, 2026
Merged

cixzhang merged 1 commit into
mainfrom
lane2/focus-return-reveal-wait-open

Conversation

@cixzhang

@cixzhang cixzhang commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Maintainer impact

FocusReturnReveal.a11y.browser.spec.ts:186, "DropdownMenu focus return › an Escape close shows an opener the page scrolled out of view", fails now and then in CI with the opener still 600px above the viewport: Expected: >= 0, Received: -600. The failing runs used Playwright's Chromium 149.0.7827.55. A failure blocks an unrelated pull request until someone re-runs it.

Intended invariant

A keyboard open moves focus into the menu, and a close from inside returns focus to the opener and scrolls it into view (revealReturnTarget). A close that comes before focus enters the surface returns no focus, because focus never left the opener (useFocusTrap: "Focus that never entered the container… is not moved"). That is correct product behavior, and this pull request does not change it.

For a person. A keyboard user can, in principle, press Escape in the same short window, on a slow device, before the menu has moved focus to its first row. Focus then never leaves the opener: the close moves no focus and scrolls nothing, so the person is exactly where they were before pressing Enter. The opener holds focus where they left it, and the page sits where they scrolled it. Reaching that state takes a focused opener the person scrolled out of view themselves, since a Tab or a click on the opener brings it into view. The reveal covers a different case, focus that the close moves back to the opener without a scroll, so this window loses nothing a person had before the open. Scrolling a page the person scrolled on purpose, on a close that moved no focus, would be a new behavior, not a repair, so this pull request does not add it.

Change

The spec's openFromKeyboard waited for the surface to be visible and for getAnimations({subtree: true}).length to be 0. On a slow runner that second poll can read 0 before the entrance animation starts, so the spec pressed Escape before the menu had moved focus to its first row. Focus then stayed on the opener, no return ran, and the opener was never revealed: toBeFocused passed and the top stayed at -600, as in both failures.

openFromKeyboard now waits for focus inside the surface, the open's own observable, before it waits for animations. No timeout changes.

Evidence

  • Failure before the change: a copy of the spec that presses Escape right after Enter, at the current base, on Chromium 156 with one worker. It failed 4 of 40 runs, each with document.activeElement on the Actions trigger before Escape and the opener's top at -600 after the close. Every run whose focus had reached the first row passed.
  • Success after the change: the whole file ×30, 420/420; ×10 under a 4× CPU throttle, 140/140.
  • Product/runtime behavior verified unchanged: no product file changes.
  • CI impact: none; no workflow changes.

Chromium 155 and later scroll the page at the open to centre the menu, which also brings the opener into view, so on those builds the unchanged spec rarely shows the race. Chromium 149, which CI runs, does not.

Scope

Components: DropdownMenu, Dialog, BottomSheet (focus-return reveal spec)

  • No intended public API, product behavior, visual direction, or policy change.
  • Product changes discovered during the work were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • FocusReturnReveal.a11y.browser.spec.ts at this head, Chromium 156, one worker: ×30 and ×10 at a 4× CPU throttle, all pass.
  • Base, unchanged spec: ×30 and ×30 at a 4× throttle, all pass on Chromium 156 (the open-time centring hides the race there); the Escape-right-after-Enter copy reproduces it 4 of 40.

@vercel

vercel Bot commented Dec 4, 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 Dec 4, 2026 4:33am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 4, 2026
@astracat-bot

astracat-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Dec 4, 2026, 4:57 AM UTC

@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 4279139

Storybook · Sandbox · built from this PR's head

Package size: no published package changed; no new dependencies.

Not run on this PR: add ci:run-visual for Visual, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@cixzhang
cixzhang marked this pull request as draft December 4, 2026 04:41
@cixzhang
cixzhang marked this pull request as ready for review December 4, 2026 04:41

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

Approved pending CI: the heavy CI, including the browser accessibility specs that run this file, starts once review passes and has not run on this head yet.

The change is test-only and matches family:overlay-dismissal FR9. DropdownMenu focuses its first row one frame after the menu shows, and a close before that leaves focus on the opener, so FR9 has nothing to return or reveal. Waiting for focus inside the surface makes every keyboard-opened close exercise the case FR9 governs, and the whole file passed 70/70 when run locally in Chromium.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Title, the spec closes a menu only after the keyboard open has moved focus in: verified. Every DropdownMenu close follows openFromKeyboard (lines 199, 216, 227), which waits for focus at lines 136-140.
  • The DropdownMenu Escape reveal case fails now and then in CI with the opener 600px above the viewport: reported. It matches that case's top ≥ 0 assertion on the base.
  • The failing runs used Playwright's Chromium 149: reported. The repository's Playwright 1.61.1 pins Chromium 149.0.7827.55.
  • A keyboard open moves focus into the menu: verified at DropdownMenu.tsx:1361-1388. The new wait asserts it, and it passed locally.
  • A close from inside returns focus to the opener and reveals it: verified. DropdownMenu.tsx:1146-1155 calls returnFocusForLastInput, which calls revealReturnTarget (focusReturn.ts:329-355), and the spec's reveal cases passed locally.
  • A close before focus enters returns no focus, as the useFocusTrap comment says: verified at useFocusTrap.ts:703-704 and focusReturn.ts:864-866. In a local reproduction the opener stayed focused 600px above the viewport.
  • That behavior is correct and this change leaves it alone: verified. FR9 returns focus only when it would otherwise be lost, and no product file changes.
  • The old helper waited for visibility and no running animations: verified at base lines 129-138.
  • The animation poll can read zero before the entrance starts: reported (the author's analysis). The fix does not depend on it.
  • The helper now waits for focus inside before the animation wait, with no timeout change: verified. Head lines 136-145 add no timeout.
  • The before and after runs (4 of 40 failures; 420/420 and 140/140 passes): reported. The counts fit the file's 14 tests, and CI runs the same spec before merge.
  • No product file and no workflow changes: verified. The only changed file is this spec.
  • Chromium 155 and later centre the menu at the open and so hide the race, while Chromium 149 does not centre: reported. In a local run on Chromium 158, a close before focus entered still left the opener 600px above the viewport, so the centring did not hide it there.
  • The scope is DropdownMenu, Dialog and BottomSheet: verified against the spec's three members (lines 51-85).
  • No public API, product behavior, visual or policy change: verified. The API report shows no change, and Core's build output is identical.
  • Product changes found during the work were removed or split: reported.
  • Public text holds no internal context: verified. Nothing matches in the title, description, branch, commit message or added lines.
  • File packages/core/src/utils/__tests__/FocusReturnReveal.a11y.browser.spec.ts: clear.

Automated review (maintainer link)

@cixzhang
cixzhang merged commit deabaff into main Dec 4, 2026
210 of 217 checks passed
@cixzhang
cixzhang deleted the lane2/focus-return-reveal-wait-open branch December 4, 2026 06:06

This branch was successfully deployed

1 active deployment
Preview — 42791392 Deployed Dec 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) 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.

1 participant