Repository navigation
test(core): the focus-return reveal spec closes a menu only after the keyboard open moved focus in - #14301
Conversation
…open has moved focus into the surface
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
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-1155callsreturnFocusForLastInput, which callsrevealReturnTarget(focusReturn.ts:329-355), and the spec's reveal cases passed locally. - A close before focus enters returns no focus, as the
useFocusTrapcomment says: verified atuseFocusTrap.ts:703-704andfocusReturn.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.
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
openFromKeyboardwaited for the surface to be visible and forgetAnimations({subtree: true}).lengthto 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:toBeFocusedpassed and the top stayed at -600, as in both failures.openFromKeyboardnow waits for focus inside the surface, the open's own observable, before it waits for animations. No timeout changes.Evidence
document.activeElementon 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.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)
Testing
FocusReturnReveal.a11y.browser.spec.tsat this head, Chromium 156, one worker: ×30 and ×10 at a 4× CPU throttle, all pass.