Skip to content

fix(BottomSheetSwitcher): a flow without its scrim, or a removed switcher, returns focus to its opener - #11982

Merged
cixzhang merged 7 commits into
mainfrom
fix/switcher-focus-return
Nov 20, 2026
Merged

cixzhang merged 7 commits into
mainfrom
fix/switcher-focus-return

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11946
Fixes #11947

User impact

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

  • A non-modal step reports the opener to the switcher just before it shows its dialog (a private onBeforeSheetShow on the switcher's context, beside the modal onBeforeSheetPresent).
  • The switcher records whether focus was in the flow in the commit that closes it. The closing step turns inert in that commit, and the browser moves focus out of it only when it next renders, so this is the last point where focus is still where the person left it (the same reading a standalone sheet makes). When the flow hides, it returns focus to the opener from that record, unless the person has since moved focus elsewhere (the native dialog's return rule, component:BottomSheet FR11).
  • A removal goes through the shared prepareFocusRepairOnRemoval and returnFocusForLastInput, 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).
  • No new public API.

Expected behavior and authority

component:BottomSheet FR11 (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-017 FR26 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 on body (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):

    Story main Before (28dd7bf: stories only) After (36e94c6, code as 48346b0)
    No scrim: Cancel from inside 1/5, mostly body 0/5, body 5/5, the opener
    Removed while open (scrim) n/a (story is new) 0/5, body 5/5, the opener
    Removed while open, no scrim n/a (story is new) 5/5 (the native close returns it) 5/5
  • Real 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.tsx cases 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 no inert, so these prove the calls; the browser rows above prove where focus ends.

  • BottomSheet suites: 625 tests pass; eslint, tsc and check:knowledge clean.

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

  • One defect class restored (switcher focus return), covering two reports on the same path.
  • Two stories ("Removed while open", with and without the scrim) back the browser spec.
  • 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.

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.

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

vercel Bot commented Nov 16, 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 Nov 20, 2026 12:29am UTC

Request Review

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

astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 20, 2026, 1:24 AM UTC

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec f783a62

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 106f070

Storybook · Sandbox · built from this PR's head

Modified components

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.

Component · story Before After Diff
BottomSheet · Text Only (neutral, dark) · inheritance unknown: not found in the 7 newest reports of other pull requests before frame after frame diff frame
BottomSheet · Text Only (neutral, light) · inheritance unknown: not found in the 7 newest reports of other pull requests before frame after frame diff frame

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

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

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 in BottomSheetSwitcher.tsx:626-632 reads document.activeElement when the flow turns invisible, which is after the exiting step's dialog has carried inert (BottomSheet.tsx:1267, :1297) and the browser has already moved focus out, so the holdsFocus guard 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-654 runs while the step's modal dialog is still open, so the page opener is inert and the focus() call is refused (the probe recorded the call with moved: false, and focus ends on <body>, as on main).
  • The removal path re-implements prepareFocusRepairOnRemoval / prepareFocusReturnOnRemoval from packages/core/src/utils/focusReturn.ts, which BottomSheet, Dialog, Drawer and Lightbox all call for this concern, and drops its isConnected guard (StrictMode), its post-commit microtask, its keepRestingFocus rule and returnFocusForLastInput'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.md replaces 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.

Automated review (maintainer link)

Comment thread .changeset/switcher-focus-return.md Resolved

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

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 at BottomSheetSwitcher.tsx:626-632 reads document.activeElement after the exiting step became inert, 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-654 calls focus() 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:42 loads core-bottomsheetswitcher-deprecated--<story>, but the stories' id is core-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 prepareFocusRepairOnRemoval from packages/core/src/utils/focusReturn.ts, which BottomSheet, Dialog, Drawer and Lightbox call, and loses its post-commit microtask, StrictMode guard, keepRestingFocus rule 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.

Automated review (maintainer link)

Comment on lines +571 to +572
// 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.

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

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

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:58 tests 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 stubs close()), 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 main focus 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 main Chromium 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 main and 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.

Automated review (maintainer link)

Comment on lines +586 to +588
// 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.

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

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 36e94c6

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

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 (the removed-while-open-no-scrim browser 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 main Chromium 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-656 and 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 main and all four pass here — verified (3 fail and 1 passes on main; 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.

Automated review (maintainer link)

@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: 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 main in 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 at BottomSheetSwitcher.tsx:615-641; standalone return at BottomSheet.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 main and 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 main after 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.

Automated review (maintainer link)

@duytbp

duytbp commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

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
(625 tests).

Two notes, neither blocking:

  • For a flow without the scrim, the return happens once the sheet's exit transition ends. In
    jsdom a test has to fire transitionend on the panel to see it (waiting out the transition
    length isn't enough), which may be worth a comment in the test for the next person.
  • Both issues mention the sheet's finalFocusRef as an alternative target. The switcher doesn't
    read a step's finalFocusRef in the modal path either, so leaving it out keeps things
    consistent; maybe a follow-up if you think it belongs.

From the reporter's side this fully resolves #11946 and #11947.

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 19, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 428669a

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 19, 2026

@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: 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 through returnFocusForLastInput.
  • The switcher tests in the BottomSheet record's FR20 verification row.
  • Miss: a ## Writing rubric results section 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 main in 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 at BottomSheet.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 main and 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 main after 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.

Automated review (maintainer link)

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

Copy link
Copy Markdown
Contributor Author

/approve-spec 106f070

@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 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 through returnFocusForLastInput.
  • The switcher tests in the BottomSheet record's FR20 verification row.
  • A ## Writing rubric results section 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 at BottomSheet.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 main and 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 main and 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.

Automated review (maintainer link)

@cixzhang
cixzhang marked this pull request as ready for review November 20, 2026 01:03
@cixzhang
cixzhang merged commit e9baa35 into main Nov 20, 2026
152 checks passed
@github-actions
github-actions Bot deleted the fix/switcher-focus-return branch November 20, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 106f0705 Deployed Nov 20, 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

2 participants