Repository navigation
fix(BottomSheetSwitcher): a flow without its scrim, or a removed switcher, returns focus to its opener - #11982
Conversation
…tcher, must return focus to its opener
…cher, returns focus to its opener
A flow with hasScrim={false} that closed with focus inside it left focus
in the hidden sheet: the switcher returned focus only for a modal flow,
and only a modal step told it the opener. A non-modal step now reports the
opener before it shows its dialog, and on close the switcher returns focus
to that opener while focus is still in the flow, as a standalone sheet
without its scrim does (component:BottomSheet FR11).
A switcher removed while a sheet was open returned no focus. It now
returns focus to the opener when focus was in the flow or fell to the body
with the removal; a sheet open above the flow keeps focus (FR20). FR20's
implementation-gap sentence becomes the rule.
The tests end the sheet's exit transition before checking focus.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
|
/approve-spec f783a62 |
PR Analysis Report🔎 Preview ·
|
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| BottomSheetSwitcher | 19.1 kB (+314 B) · 3.4 kB CSS (0) | — | ✗ · ✓ · — |
| BottomSheet | 75.3 kB (+22 B) · 7.8 kB CSS (0) | — | ✗ · ✓ · — |
| DateInput | 203.7 kB (+37 B) · 18.1 kB CSS (0) | — | — · — · — |
21 more components
| Component | Size | LoC | Visual · A11y · RTL |
|---|---|---|---|
| DateTimeInput | 227.2 kB (+36 B) · 19.8 kB CSS (0) | — | — · — · — |
| PowerSearch | 311.6 kB (+28 B) · 25.8 kB CSS (0) | — | — · — · — |
| TimeInput | 178.4 kB (+15 B) · 17.0 kB CSS (0) | — | — · — · — |
| Markdown | 206.1 kB (+1 B) · 22.4 kB CSS (0) | — | — · — · — |
| Tokenizer | 106.4 kB (+1 B) · 20.5 kB CSS (0) | — | — · — · — |
| ContextMenu | 104.0 kB (0) · 19.0 kB CSS (0) | — | — · — · — |
| MoreMenu | 109.7 kB (0) · 19.2 kB CSS (0) | — | — · — · — |
| MultiSelector | 104.3 kB (0) · 18.1 kB CSS (0) | — | — · — · — |
| Pagination | 148.6 kB (0) · 19.3 kB CSS (0) | — | — · — · — |
| Popover | 100.7 kB (0) · 15.2 kB CSS (0) | — | — · — · — |
| Selector | 115.7 kB (0) · 18.9 kB CSS (0) | — | — · — · — |
| TableCell | 105.2 kB (0) · 19.5 kB CSS (0) | — | — · — · — |
| TableHeaderCell | 105.0 kB (0) · 19.4 kB CSS (0) | — | — · — · — |
| lab/ChatEmojiPicker | 123.1 kB (0) · 773 B CSS (0) | — | — · — · — |
| lab/ChatReactionBar | 124.3 kB (0) · 1.1 kB CSS (0) | — | — · — · — |
| lab/CommentComposer | 181.3 kB (0) · 1.9 kB CSS (0) | — | — · — · — |
| lab/Comments | 380.6 kB (0) · 2.5 kB CSS (0) | — | — · — · — |
| richtext/RichTextEditorToolbar | 310.4 kB (0) · 454 B CSS (0) | — | — · — · — |
| DropdownMenu | 109.5 kB (−1 B) · 19.2 kB CSS (0) | — | — · — · — |
| Table | 122.3 kB (−1 B) · 20.1 kB CSS (0) | — | — · — · — |
| lab/CommentThread | 373.6 kB (−1 B) · 2.4 kB CSS (0) | — | — · — · — |
Visual changes: 2 snapshots in 1 component
A change is a question for the reviewer, not a failure.
Inheritance checked against the 7 newest reports of other pull requests.
Package size: @astryxdesign/core 7.72 MB packed (+1.2 kB); no new dependencies.
Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-rtl for RTL.
Generated by PR Enrichment workflow | View full report
There was a problem hiding this comment.
Changes requested. The two reported defects are still present when the code runs in Chromium at this head; the new cases pass only in jsdom, where the test suite replaces the dialog methods with stubs that implement neither inertness nor the native focus return.
- A
hasScrim={false}flow closed with focus inside it still ends with focus on<body>: the return inBottomSheetSwitcher.tsx:626-632readsdocument.activeElementwhen the flow turns invisible, which is after the exiting step's dialog has carriedinert(BottomSheet.tsx:1267,:1297) and the browser has already moved focus out, so theholdsFocusguard is false and the opener is never focused. - A switcher removed while a sheet is open with the default scrim still returns no focus: the cleanup at
BottomSheetSwitcher.tsx:642-654runs while the step's modal dialog is still open, so the page opener is inert and thefocus()call is refused (the probe recorded the call withmoved: false, and focus ends on<body>, as onmain). - The removal path re-implements
prepareFocusRepairOnRemoval/prepareFocusReturnOnRemovalfrompackages/core/src/utils/focusReturn.ts, whichBottomSheet,Dialog,DrawerandLightboxall call for this concern, and drops itsisConnectedguard (StrictMode), its post-commit microtask, itskeepRestingFocusrule andreturnFocusForLastInput's ring handling — call the shared helper instead of keeping a second path. - The changeset and the User impact section state that both cases now return focus to the opener, and
docs/specs/components/BottomSheet/BottomSheet.spec.mdreplaces FR20's implementation-gap sentence with the fixed rule, so the release note and the contract describe behaviour the change does not deliver; the no-scrim removal case they also claim already behaved that way before this change.
Two concrete routes: capture whether focus was inside the flow in the commit where activeSheet turns null, before the step is marked inert — the pattern BottomSheet.tsx:686-693 uses with hadFocusAtCloseRef — and use the shared removal helper for the unmount path. FR20's verification row asks for a real-browser focus check in Chromium for this rule; a Playwright or browser spec covering both cases would have caught each of these before review.
Claims and files checked
Review mode: full; reason: no-earlier-review
Claims
- Changeset: a no-scrim flow closing with focus inside now returns focus to the opener — false in Chromium (focus ends on
<body>); true under the jsdom stubs. - Changeset: a switcher removed while a sheet is open returns focus to the opener with or without the scrim — false with the scrim in Chromium; true without it, where the base already did so.
- Description: the cause of both reports (return guarded by the modal flag, only a modal present records the opener, nothing covers unmount) — verified against the source at the merge base.
- Description: a non-modal step reports the opener before showing its dialog, through a private context member — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:582). - Description: a sheet open above the flow keeps focus on removal — verified as written in the guard.
- Description: no new public API — verified; the surface generator reports zero added, changed or removed rows for every published package.
- Description: red-first, the three return cases fail on the base and all four pass here — verified (base plus these tests: 3 failed, 53 passed; head: 56 passed).
- Description: the BottomSheet suites pass (625 tests) and eslint, the type check and the knowledge check are clean — all verified at this head.
- Description: overlap with the three named pull requests does not touch the focus-return path — verified from their diffs (one adds Tab containment, one changes scrim-press dismissal, one is records only).
- Description: no internal context in public text or artifacts — verified over the title, body, branch name, commit messages and every added line.
Files
.changeset/switcher-focus-return.md— finding: states behaviour the change does not deliver.docs/specs/components/BottomSheet/BottomSheet.spec.md— finding: FR20's gap sentence is replaced by a rule the implementation does not meet in a browser; owner-approved for this head, and no approval line changes.packages/core/src/BottomSheet/BottomSheet.tsx— clear: the three lines add the non-modal opener report beside the modal one.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— findings: both return paths and the duplicated helper.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— finding: jsdom-only evidence that cannot see either defect.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear: one private context member, documented and wired into the memo.
…-scrim close and after a removal
There was a problem hiding this comment.
Changes requested. Both focus returns still fail in Chromium at this head, and the browser spec added since the last review cannot show it, because it never loads the stories it tests.
- A
hasScrim={false}flow closed from inside still ends with focus on<body>: the return atBottomSheetSwitcher.tsx:626-632readsdocument.activeElementafter the exiting step becameinert, so the browser has already moved focus out and the guard is false. - A switcher removed while a sheet is open with the default scrim still returns no focus: the cleanup at
BottomSheetSwitcher.tsx:642-654callsfocus()while the step's modal dialog is still open, so the inert opener refuses it and focus ends on<body>, as before. BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts:42loadscore-bottomsheetswitcher-deprecated--<story>, but the stories' id iscore-bottomsheetswitcher, so all three tests fail at the opener; its no-scrim test also uses a story whose play function opens the flow by script on load, so when the play function wins the race the flow records<body>as its opener and the test's Enter finds the sheet already open.- The removal path re-implements
prepareFocusRepairOnRemovalfrompackages/core/src/utils/focusReturn.ts, which BottomSheet, Dialog, Drawer and Lightbox call, and loses its post-commit microtask, StrictMode guard,keepRestingFocusrule and focus-ring handling, so call the helper instead. - The changeset, the description's User impact and the FR20 rewrite say both cases now return focus to the opener, which the browser does not do, and the no-scrim removal already did so before this change.
A workable order: fix the spec's story ids so it fails on the two defects, then record whether focus was inside the flow in the commit that closes it (as hadFocusAtCloseRef does in BottomSheet.tsx) and use the shared removal helper for the unmount.
Claims and files checked
Review mode: incremental; reason: none
changed rules (0)
Claims
- Changeset: a no-scrim flow closing with focus inside now returns focus to its opener — false in Chromium (focus ends on the page body); true only under the jsdom dialog stubs.
- Changeset: a switcher removed while a sheet is open returns focus to the opener with or without the scrim — false with the scrim; true without it, as it already was.
- Description: the cause of both reports (return only for a modal flow, only a modal present records the opener, nothing on unmount) — verified against the base source.
- Description: a non-modal step reports the opener just before it shows its dialog, through a private context member — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:582). - Description: focus moved elsewhere stays when a no-scrim flow hides — verified in the code guard and the jsdom case.
- Description: a sheet open above the flow keeps focus on removal — verified as written in the guard.
- Description: no new public API — verified; the surface generator reports no added, changed or removed rows.
- Description: red first, the three return cases fail on the base and all four pass here — verified in jsdom: the head suite passes here (56 tests), and the base run with these tests (3 failures) comes from the previous revision, unchanged since.
- Description: the BottomSheet suites pass and lint, type and knowledge checks are clean — the switcher suite re-run here passes; the rest comes from the previous revision, whose source is identical.
- Description: the three overlapping pull requests do not touch the focus-return path — verified at the previous revision; unchanged.
- Description: no internal context in public text — verified over the title, body, branch, commit messages and every added line.
- Browser spec header: browser evidence that both returns work, with and without the scrim — false; the spec loads missing stories, and on the real stories two of the three cases end on the page body.
Files
.changeset/switcher-focus-return.md— finding: states behaviour the change does not deliver.apps/storybook/stories/BottomSheetSwitcher.stories.tsx— the two new stories render and probe as described; their comment repeats the unmet claim, and the spec pairs its no-scrim test with a story that opens by script.docs/specs/components/BottomSheet/BottomSheet.spec.md— finding: the FR20 rule is not met in a browser; owner-approved, no approval line changes.packages/core/src/BottomSheet/BottomSheet.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— evidence gap: jsdom-only cases with stubbed dialog methods.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— findings: both return paths and the copied removal helper; two comments over the style guide's length.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear.packages/core/src/BottomSheet/__tests__/BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts— finding: wrong story ids and a pre-opened story.
| // The step dialogs can render outside the flow's element, so focus counts as | ||
| // inside the flow when the flow or one of its step dialogs holds it. |
There was a problem hiding this comment.
Non-blocking (INV29): this sentence has 27 words, over the 25-word limit for a description. Suggested: "Step dialogs can render outside the flow element. Focus is in the flow when the flow or a step dialog holds it."
…fter the commit In a browser the previous return paths never ran. A flow without its scrim read focus when it turned hidden, after the closing step had been inert and the browser had moved focus to the body. A removed switcher focused its opener while the step's modal dialog still made the page inert. The switcher now records whether focus was in the flow in the commit that closes it, before the browser moves focus, and returns focus to the opener from that record. A removal goes through the shared prepareFocusRepairOnRemoval and returnFocusForLastInput, as a standalone sheet's does: the repair runs after the commit, once the dialog has closed, and skips StrictMode's simulated unmount and focus that already rested on the body. The jsdom removal cases wait for that repair, and the browser spec's story id is corrected.
There was a problem hiding this comment.
Changes requested. Both focus returns now work in a browser: a hasScrim={false} flow closed from inside, and a switcher removed while its modal sheet is open, both put focus back on the opener in Chromium and Firefox, and the removal now uses the shared repair. Two things remain:
BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts:58tests the "No scrim" story, whose play function opens the flow by script on load, so when it runs first the flow records the page body as its opener and the test fails on correct code; use a no-scrim story without a play step, or close the scripted flow before focusing the opener.- The description's User impact says a removed switcher dropped focus "with or without the scrim", but without the scrim the step dialog's own close already returned focus on
main(the jsdom case fails there only because the suite stubsclose()), so narrow it to the scrim case as the release note now does.
Claims and files checked
Review mode: incremental; reason: none
changed rules (0)
Claims
- Release note: a no-scrim flow that closes with focus inside now returns focus to its opener instead of leaving it on the page body — verified in Chromium and Firefox, keyboard and pointer; focus moved elsewhere stays.
- Release note: a switcher with its scrim removed while a sheet is open now returns focus to the opener — verified in Chromium and Firefox; on
mainfocus ends on the page body. - Description, user impact of the no-scrim close: focus was not returned and now goes back to the opener — verified; on
mainChromium reports the page body as focused once the step is inert. - Description, user impact of the removal: focus dropped "with or without the scrim" — false without the scrim (finding above).
- Description, cause: only a modal flow returned focus and nothing ran on unmount — verified against the base source.
- Description, fix: a non-modal step reports the opener just before it shows its dialog — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:598-602). - Description, fix: a no-scrim flow returns focus only while focus is still in the flow, and focus moved elsewhere stays — verified in the browser.
- Description, fix: on unmount focus returns when it was in the flow or fell to the body, and a sheet open above keeps focus — verified in the shared removal helper's code and, for the return, in the browser.
- Description: no new public API — verified; the built surfaces of core, build and every published theme are unchanged.
- Description: red first, the three return cases fail on
mainand all four pass here — verified (3 fail on the base with these tests; 56 pass here). - Description: the BottomSheet suites pass (625 tests) and lint, type and knowledge checks are clean — verified: 625 pass, lint is clean on the changed files, and the package build's type check and the knowledge check pass.
- Description: the three overlapping pull requests do not touch the focus-return path — verified at the previous revision; this revision does not change that.
- Description: no internal context in public text — verified over the title, body, branch, commit messages and every added line.
- Browser spec header: browser evidence for both returns, with and without the scrim — the removal tests match the browser results; the no-scrim test is unreliable (finding above).
Files
.changeset/switcher-focus-return.md— clear.apps/storybook/stories/BottomSheetSwitcher.stories.tsx— clear; the existing "No scrim" story's play step is what the spec races.docs/specs/components/BottomSheet/BottomSheet.spec.md— clear; the owner-approved FR20 rule is met in the browser.packages/core/src/BottomSheet/BottomSheet.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— clear; two non-blocking comment-length notes.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear.packages/core/src/BottomSheet/__tests__/BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts— finding: the no-scrim test races the story's play step.
| // Whether focus was in the flow when the flow closed. Read in the commit | ||
| // that closes it: the closing step is marked inert in that commit, and the | ||
| // browser moves focus out of it only when it next renders. |
There was a problem hiding this comment.
Non-blocking (INV29): the second sentence has 29 words, over the 25-word limit for a description, and uses the passive ("is marked inert"). Suggested: "Read it in the closing commit. That commit makes the closing step inert. The browser moves focus out of the step at the next render."
…e before the browser checks
|
/approve-spec 36e94c6 |
There was a problem hiding this comment.
Changes requested. Both focus returns work in Chromium, and the browser spec's no-scrim test now closes the story's scripted flow first, so it passes on this head and fails on main as it should. One thing remains:
- The description's User impact says a removed switcher dropped focus "with or without the scrim", but without the scrim the step dialog's own close already returned focus on
main(theremoved-while-open-no-scrimbrowser test passes there), so narrow it to the scrim case, as the release note does.
Claims and files checked
Review mode: incremental; reason: none
changed rules (0)
Claims
- Release note: a no-scrim flow that closes with focus inside now returns focus to its opener instead of the page body — verified: the browser spec's no-scrim test passes on this head (3 of 3) and fails on
main. - Release note: a switcher with its scrim removed while a sheet is open now returns focus to the opener — verified: the scrim removal test passes here and fails on
main. - Description, user impact of the no-scrim close: focus was not returned and now goes back to the opener — verified; on
mainChromium leaves the page body focused. - Description, user impact of the removal: focus dropped "with or without the scrim" — false without the scrim (finding above).
- Description, cause: only a modal flow returned focus and nothing ran on unmount — verified against the base source.
- Description, fix: a non-modal step reports the opener just before it shows its dialog — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:598-602). - Description, fix: a no-scrim flow returns focus only while focus is still in the flow, and focus moved elsewhere stays — verified (
BottomSheetSwitcher.tsx:642-656and the jsdom case with focus outside). - Description, fix: on unmount focus returns when it was in the flow or fell to the body, and a sheet open above keeps focus — verified in the shared removal helper and, for the return, in the browser.
- Description: no new public API — verified; the new context member is not exported.
- Description, red first: the three return cases fail on
mainand all four pass here — verified (3 fail and 1 passes onmain; 4 pass here). - Description: the BottomSheet suites pass (625 tests) and lint, type and knowledge checks are clean — verified at this head.
- Description: the three named overlapping pull requests do not touch the focus-return path — verified from their changed files.
- Description: no internal context in public text — verified over the title, body, branch, commit messages and every added line.
- Browser spec header: browser evidence for both returns, with and without the scrim — verified: 9 of 9 pass at this head.
Files
.changeset/switcher-focus-return.md— clear.apps/storybook/stories/BottomSheetSwitcher.stories.tsx— clear.docs/specs/components/BottomSheet/BottomSheet.spec.md— clear; the owner-approved FR20 rule is met in the browser.packages/core/src/BottomSheet/BottomSheet.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— clear; two non-blocking comment-length notes.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear.packages/core/src/BottomSheet/__tests__/BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts— clear; the play-function race is fixed.
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet. Both focus returns work: a hasScrim={false} flow closed from inside, and a switcher with its scrim removed while a sheet is open, both return focus to the opener in Chromium and Firefox, and the description matches what main already did without the scrim.
Optional follow-ups, none blocking: the two comment rewrites in the open inline suggestions, a useInteractionModalityTracking() call in the switcher now that it returns focus through returnFocusForLastInput, and the switcher tests in FR20's verification row.
Claims and files checked
Review mode: same-head; reason: none
changed rules (0)
Claims
- Release note: a no-scrim flow that closes with focus inside returns focus to its opener instead of the page body — verified: the browser spec's no-scrim test passes on this head in Chromium and Firefox and fails on
main. - Release note: a switcher with its scrim that is removed while a sheet is open returns focus to the opener when the removal lost it — verified: the scrim removal test passes here and fails on
mainin both engines. - Description, impact of the no-scrim close: focus fell to the page body and now returns to the opener, as it does for a modal flow and a standalone no-scrim sheet — verified (focus ends on the body on
main; modal return atBottomSheetSwitcher.tsx:615-641; standalone return atBottomSheet.tsx:788-797). - Description, impact of the removal: only the scrim case dropped focus; without the scrim the step dialog's own close already returned it and still does — verified: the no-scrim removal test passes on
mainand here. - Description: both issues were reported, with reproductions, by the same contributor — verified from the two linked issues.
- Description, cause: only a modal flow returned focus, and only modal steps reported the opener — verified against
main's source. - Description, fix: a non-modal step reports the opener just before it shows its dialog — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:598-602). - Description, fix: focus is read in the closing commit and returned unless the person moved it elsewhere — verified (
BottomSheetSwitcher.tsx:586-597,:642-656, and the jsdom case with focus outside). - Description, fix: a removal goes through the shared after-commit repair that the standalone sheet, Dialog, Drawer and Lightbox use, which skips StrictMode's simulated unmount and focus already resting on the body — verified (
BottomSheetSwitcher.tsx:663-682,utils/focusReturn.ts:212-238). - Description: no new public API — verified; the new context member is not exported.
- Description, authority: BottomSheet FR11 and FR20 govern, FR12 covers only modal flows, both cases are defects against the records, and the deprecated switcher stays supported until removal — verified against the current records; the FR20 edit has an engineering owner's approval at this head.
- Description, browser evidence before: Chromium and Firefox end on the body on
mainafter a no-scrim close — verified; the WebKit counts could not be reproduced in this review. - Description, browser evidence after: focus returns to the opener in all three stories — verified in Chromium and Firefox; WebKit not reproduced.
- Description, Chrome take counts per commit: the evidence table's commits match their contents and its outcomes match the runs here (body before, opener after); the exact take counts were not reproduced.
- Description, jsdom: the test commit came first, and the cases prove the calls — verified (3 fail and 1 passes on
main; all 4 pass here). - Description: the BottomSheet suites pass (625 tests) and lint, type and knowledge checks are clean — verified at this head.
- Description: the three named overlapping pull requests do not touch the focus-return path — verified from their patches.
- Description: no internal context in public text — verified over the title, body, branch, commit messages and every added line.
- Browser spec header: browser evidence for both returns, with and without the scrim — verified: every run passes at this head.
Files
.changeset/switcher-focus-return.md— clear.apps/storybook/stories/BottomSheetSwitcher.stories.tsx— clear.docs/specs/components/BottomSheet/BottomSheet.spec.md— clear; the owner-approved FR20 sentence is met in the browser.packages/core/src/BottomSheet/BottomSheet.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— clear; two non-blocking comment-length notes and one modality-tracking note.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear.packages/core/src/BottomSheet/__tests__/BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts— clear.
|
Thanks, and for covering both reports in one place. On the head I ran:
Six of those eight fail on the merge base and all pass here; the BottomSheet suites pass Two notes, neither blocking:
From the reporter's side this fully resolves #11946 and #11947. |
|
/approve-spec 428669a |
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet. Both focus returns work: a hasScrim={false} flow closed from inside, and a switcher with its scrim removed while a sheet is open, return focus to the opener in Chromium and Firefox, and both end on the page body on main.
Optional follow-ups, none blocking:
- The two comment rewrites in the open inline suggestions.
- A
useInteractionModalityTracking()call in the switcher, since it now returns focus throughreturnFocusForLastInput. - The switcher tests in the BottomSheet record's FR20 verification row.
- Miss: a
## Writing rubric resultssection in the description, which a record change asks for; the changed FR20 sentence passes the rubric.
Claims and files checked
Review mode: full; reason: merge-touches-pr-files
Claims
- Release note: a no-scrim flow that closes with focus inside returns focus to its opener instead of the page body — verified: the browser spec's no-scrim test passes on this head in Chromium and Firefox and fails on
main, where focus ends on the body. - Release note: a switcher with its scrim that is removed while a sheet is open returns focus to the opener when the removal lost it — verified: the scrim removal test passes here and fails on
mainin both engines. - Description, impact of the no-scrim close: focus fell to the page body and now returns to the opener, as for a modal flow and a standalone no-scrim sheet — verified (modal return at
BottomSheetSwitcher.tsx:615-641; standalone return atBottomSheet.tsx:788-797). - Description, impact of the removal: only the scrim case dropped focus; without the scrim the step dialog's own close already returned it and still does — verified: the no-scrim removal test passes on
mainand here. - Description: both issues were reported, with reproductions, by the same contributor — verified from the two linked issues.
- Description, cause: only a modal flow returned focus, and only modal steps reported the opener — verified against
main's source. - Description, fix: a non-modal step reports the opener just before it shows its dialog — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:598-602). - Description, fix: focus is read in the closing commit and returned unless the person moved it elsewhere — verified (
BottomSheetSwitcher.tsx:586-597,:642-656, and the jsdom case with focus outside). - Description, fix: a removal goes through the shared after-commit repair, which skips StrictMode's simulated unmount and focus already resting on the body — verified (
BottomSheetSwitcher.tsx:663-682,utils/focusReturn.ts:212-239). - Description: no new public API — verified: the API report generator lists no changed rows, and the new context member is not exported.
- Description, authority: BottomSheet FR11 and FR20 govern, FR12 covers only modal flows, and the deprecated switcher stays supported until removal — verified against the current records; an engineering owner approved the FR20 edit at this head.
- Description, browser evidence before: Chromium and Firefox end on the body on
mainafter a no-scrim close — verified; the WebKit counts were not reproduced. - Description, Chrome before and after table: its outcomes match the runs here (body before, opener after); the preview take counts were not reproduced.
- Description, browser evidence after: focus returns to the opener in all three stories — verified in Chromium and Firefox, 3 takes each; WebKit not reproduced.
- Description, jsdom: the test commit came first, and the cases prove the calls — verified (3 fail and 1 passes on
main; all 4 pass here). - Description: the BottomSheet suites pass (625 tests) and lint, type and knowledge checks are clean — verified at this head.
- Description: the three named overlapping pull requests do not touch the focus-return path — verified from their patches.
- Description: no internal context in public text — verified over the title, body, branch, commit messages and every added line.
- Browser spec header: browser evidence for both returns, with and without the scrim — verified: every run passes at this head.
Files
.changeset/switcher-focus-return.md— clear.apps/storybook/stories/BottomSheetSwitcher.stories.tsx— clear.docs/specs/components/BottomSheet/BottomSheet.spec.md— clear; the owner-approved FR20 sentence is met in the browser; verification-row note.packages/core/src/BottomSheet/BottomSheet.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— clear; two comment-length notes and one modality-tracking note.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear.packages/core/src/BottomSheet/__tests__/BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts— clear.
|
/approve-spec 106f070 |
There was a problem hiding this comment.
Approved pending CI: the required checks are still running on this head. Both focus returns work: a hasScrim={false} flow closed from inside, and a switcher with its scrim removed while a sheet is open, return focus to the opener in Chromium, and both end on the page body on main.
Optional follow-ups, none blocking:
- The two comment rewrites in the open inline suggestions.
- A
useInteractionModalityTracking()call in the switcher, since it returns focus throughreturnFocusForLastInput. - The switcher tests in the BottomSheet record's FR20 verification row.
- A
## Writing rubric resultssection in the description, which a record change asks for; the changed FR20 sentence passes the rubric.
Claims and files checked
Review mode: same-head; reason: none
changed rules (0): none
Claims
- Release note: a no-scrim flow that closes with focus inside returns focus to its opener instead of the page body — verified: the browser spec's no-scrim test passes on this head in Chromium and fails on
main, where focus ends on the body. - Release note: a switcher with its scrim that is removed while a sheet is open returns focus to the opener when the removal lost it — verified: the scrim removal test passes here and fails on
main. - Description, impact of the no-scrim close: focus fell to the page body and now returns to the opener, as for a modal flow and a standalone no-scrim sheet — verified (modal return at
BottomSheetSwitcher.tsx:617-643; standalone return atBottomSheet.tsx:788-797). - Description, impact of the removal: only the scrim case dropped focus; without the scrim the step dialog's own close already returned it and still does — verified: the no-scrim removal test passes on
mainand here. - Description, cause: only a modal flow returned focus, and only modal steps reported the opener — verified against
main's source. - Description, fix: a non-modal step reports the opener just before it shows its dialog — verified (
BottomSheet.tsx:1170,BottomSheetSwitcher.tsx:600-604). - Description, fix: focus is read in the closing commit and returned unless the person moved it elsewhere — verified (
BottomSheetSwitcher.tsx:586-599,:644-658, and the jsdom case with focus outside). - Description, fix: a removal goes through the shared after-commit repair, as the standalone sheet, Dialog, Drawer and Lightbox do, skipping StrictMode's simulated unmount and focus already resting on the body — verified (
BottomSheetSwitcher.tsx:665-684,utils/focusReturn.ts:212-275). - Description: no new public API — verified: the API generator and CI's own API delta list no changed rows, and the new context member is not exported.
- Description, authority: BottomSheet FR11 and FR20 govern, FR12 covers only modal flows, and the deprecated switcher stays supported until removal — verified against the current records; an engineering owner approved the FR20 edit at this head.
- Description, browser evidence before and after: Chromium ends on the body on
mainand on the opener here in all three stories — verified, 3 takes each; the Firefox, WebKit and preview take counts were not reproduced at this head. - Description, jsdom: the cases prove the calls — verified (3 fail and 1 passes on
main; all 4 pass here). - Description: the BottomSheet suites pass (625 tests) and lint, type and knowledge checks are clean — verified at this head.
- Description: the three named overlapping pull requests do not touch the focus-return path — verified from their patches.
- Description: no internal context in public text — verified over the title, body, branch, commit messages and every added line.
- Latest commit: the focus-at-close Effect names the system it syncs — verified (
BottomSheetSwitcher.tsx:591-592).
Files
.changeset/switcher-focus-return.md— clear.apps/storybook/stories/BottomSheetSwitcher.stories.tsx— clear.docs/specs/components/BottomSheet/BottomSheet.spec.md— clear; the owner-approved FR20 sentence is met in the browser; verification-row note.packages/core/src/BottomSheet/BottomSheet.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx— clear.packages/core/src/BottomSheet/BottomSheetSwitcher.tsx— clear; two comment-length notes and one modality-tracking note.packages/core/src/BottomSheet/BottomSheetSwitcherContext.ts— clear.packages/core/src/BottomSheet/__tests__/BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts— clear.






Fixes #11946
Fixes #11947
User impact
BottomSheetSwitcherflow withhasScrim={false}that closed with focus inside it lost keyboard focus to the page body, so a keyboard or screen-reader user started over from the top of the page. Focus now goes back to the element that opened the flow, as it already does for a modal flow and for a standalone sheet without its scrim.Both reported by @duytbp, with reproductions.
Cause
The switcher returned focus only from its focus-return effect, only for a modal flow, and only modal steps told it which element opened the flow. Nothing returned focus for a flow without the scrim, or when the switcher itself unmounted.
Fix
onBeforeSheetShowon the switcher's context, beside the modalonBeforeSheetPresent).component:BottomSheetFR11).prepareFocusRepairOnRemovalandreturnFocusForLastInput, as a standalone sheet, Dialog, Drawer and Lightbox do: the repair runs after the commit, once the step's dialog has closed and the page is no longer inert, and only when the removal lost focus; it skips StrictMode's simulated unmount and focus that already rested on the body (FR20).Expected behavior and authority
component:BottomSheetFR11 (a non-modal close returns focus to the element focused at show while focus is still inside; FR12 carves out only modal flows) and FR20 (a sheet removed while open returns focus; FR20 named the switcher removal an implementation gap, and this PR turns that sentence into the rule). The Specification session ruled both records-decided defects;spec:AST-017FR26 keeps the deprecated switcher's behavior supported until removal.Evidence
Real browsers, before. Steps on the "No scrim" story: let the story's own play-opened flow finish closing, focus "Set up notifications", press Enter, wait until the sheet holds focus, focus "Cancel" in the sheet, press Enter, then read where focus ends about 1.5 s later. On
main, Chromium and Firefox end onbody(3/3 each), and WebKit returns focus to the opener (3/3).Real Chrome, before and after (Vercel preview Storybooks, 5 takes each; the steps of the new
BottomSheetSwitcherFocusReturn.a11y.browser.spec.ts):mainbodybodybodyReal browsers, after (this head's preview Storybook; the same steps, plus the two "Removed while open" stories): focus returns to "Set up notifications" in 27/27 takes (3 stories × Chromium, Firefox and WebKit × 3 takes).
jsdom (16d43ad red first):
BottomSheetSwitcher.test.tsxcases for a non-modal close with focus inside and outside, and a removal with and without the scrim. jsdom stubs the dialog methods and has noinert, so these prove the calls; the browser rows above prove where focus ends.BottomSheet suites: 625 tests pass; eslint, tsc and
check:knowledgeclean.Overlap checked
Overlap checked: #11611, #11279, #10302 (#11611 changes when a scrim press dismisses a sheet, not focus return; #11279 contains Tab inside a modal switcher step and does not touch the focus-return path; #10302 is the Tab-wrap spec for modal steps and does not touch FR11 or FR20)
Scope
Owner and land path
Owner: fix lane 2 (#11947 handed over by fix lane 3 for one PR). Land path: Specs stamp, CodeBunny review, ready when CodeBunny approves this head, required checks, then the merge queue.