Skip to content

fix(bottom-sheet): contain focus in switcher modal - #11279

Open
bezabyte wants to merge 1 commit into
meta:mainfrom
bezabyte:fix/issue-10238-switcher-focus
Open

bezabyte wants to merge 1 commit into
meta:mainfrom
bezabyte:fix/issue-10238-switcher-focus

Conversation

@bezabyte

Copy link
Copy Markdown
Contributor

Primary intent

Fix #10238 by keeping keyboard focus inside the active modal sheet rendered by BottomSheetSwitcher.

User or maintainer impact

In a modal switcher flow, Tab from the last control and Shift+Tab from the first control could leave the sheet instead of wrapping. Keyboard users could reach the browser chrome or background page before the focus cycle returned.

Authority

  • Issue #10238
  • Standalone BottomSheet already uses the shared focus-region containment hook for this behavior.

Change

  • Apply the shared focus-region containment hook to the switcher’s current host dialog while the flow is modal.
  • Preserve the existing native-dialog behavior for a modal with no tabbable controls.
  • Add a regression test covering Tab and Shift+Tab at both ends of an active switcher sheet.
  • Add a patch changeset for @astryxdesign/core.

Evidence

State Before After
Tab from the last control Focus could leave the sheet Focus wraps to the first control
Shift+Tab from the first control Focus could leave the sheet Focus wraps to the last control
Modal with no tabbable controls Native dialog behavior Native dialog behavior is preserved

This is keyboard-focus behavior rather than a visual change, so a screenshot would not reliably demonstrate the fix. The regression test asserts both focus destinations and the prevented key event.

Scope

Components: BottomSheetSwitcher; shared internal focus-region containment hook

  • This PR has one primary intent.
  • Independently removable API, visual, layout, behavior, cleanup, and policy changes were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm exec vitest run --project ui packages/core/src/BottomSheet/BottomSheetSwitcher.test.tsx --maxWorkers=1 — 53 passed.
  • pnpm -F @astryxdesign/core typecheck — passed.
  • Targeted ESLint — passed.
  • pnpm check:changesets && pnpm review:pre — passed.
  • Full repository pre-commit checks — passed.

Closes #10238.

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

vercel Bot commented Nov 11, 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 11, 2026 4:51pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟡 Reviewed (for maintainers only) Nov 11, 2026, 5:01 PM UTC

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Nov 11, 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.

Changes requested: two findings block this as written.

  • BottomSheetSwitcher.tsx:471 adds script Tab containment to switcher steps, but the current records keep those steps on native showModal() containment: component:BottomSheetSwitcher FR5 and DEC-1 (which rejects a script focus trap on top of native containment), and component:Dialog DEC-2 and component:BottomSheet FR16, which name the switcher step as the one exception to the shared focus region.
  • The changeset says the switcher now matches standalone BottomSheet, but in a step with no tabbable controls preserveNativeEmptyRegion still leaves Tab to the browser, while a standalone modal sheet keeps focus on its panel.

The switcher is deprecated, and its documented replacement (one standalone BottomSheet per step) already wraps Tab. If engineering owners decide switcher steps should join the shared focus region, those records need amending first, and this PR would then also update the switcher record, narrow the changeset or drop the empty-step option, and fix the comments that still describe native containment (BottomSheetSwitcher.tsx:474-477, BottomSheetSwitcher.test.tsx:956-958).

Automated review (maintainer link)

// Native modal dialogs provide this boundary in the browser, but the
// switcher's host moves between child dialogs during a flow. Keep the same
// Tab containment as a standalone BottomSheet on every active host.
useFocusRegionContainment(hostDialogRef, isModal, {

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.

This adds script Tab containment to every modal switcher step. component:BottomSheetSwitcher FR5 and DEC-1 keep switcher steps on native showModal() containment (DEC-1 rejects "a script focus trap on top of native containment"). component:Dialog DEC-2 and component:BottomSheet FR16 name the switcher step as the one exception to the shared focus region. Drop this call and the hook option, or have an engineering owner amend those records first.

'@astryxdesign/core': patch
---

[fix] BottomSheetSwitcher now keeps Tab and Shift+Tab inside its active modal sheet, matching standalone BottomSheet.

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.

In a step with no tabbable controls, preserveNativeEmptyRegion still leaves Tab to the browser, while a standalone modal BottomSheet cancels the press and keeps focus on its panel. So "matching standalone BottomSheet" does not hold there. Either say "in a step with tabbable controls", or drop the option so empty steps match.

Comment on lines +468 to 476
// Native modal dialogs provide this boundary in the browser, but the
// switcher's host moves between child dialogs during a flow. Keep the same
// Tab containment as a standalone BottomSheet on every active host.
useFocusRegionContainment(hostDialogRef, isModal, {
preserveNativeEmptyRegion: true,
});
// Focus containment is the native modal dialog's: showModal() makes the
// page inert, so Tab cannot leave the active sheet. The released read-only
// `hasActiveFocusTrapEscape()` signal still reports a modal flow as a trap,

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: the existing comment at 474 still says Tab cannot leave the active sheet because containment is native, which the call above now contradicts. The new comment's reason (the host moving between dialogs) is also not why native containment lets Tab out. A shorter version: "showModal() lets Tab reach the browser's own stops. Wrap it in the active step."

@bezabyte

Copy link
Copy Markdown
Contributor Author

I reviewed the requested changes against the current component records before changing this branch.

I am leaving the implementation unchanged for now because the review identifies a contract conflict rather than an isolated bug: BottomSheetSwitcher and Dialog currently require native showModal() containment for switcher steps, while this PR adds a script focus trap. The records also require the empty-step behavior to be decided before changing the fallback.

An engineering owner needs to choose whether deprecated switcher steps should join the shared focus region. If that decision changes the records, I can update the switcher spec, comments, changeset scope, and empty-step behavior together. Until then, changing only the implementation would knowingly violate the current contract.

This branch was successfully deployed

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

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] BottomSheetSwitcher: Tab from a sheet's last control leaves the modal

1 participant