Skip to content

fix(useFocusTrap): a modal focus region's Tab cycle skips elements with a negative tabindex - #12265

Merged
cixzhang merged 3 commits into
mainfrom
lane2/focus-region-tabindex
Nov 26, 2026
Merged

cixzhang merged 3 commits into
mainfrom
lane2/focus-region-tabindex

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Owner: fix lane 2. Land path: draft → Specs check → CodeBunny → merge queue.

Fixes #11957. @jimmyallinai claimed the issue on November 16 and proposed this fix. No pull request followed the claim, so fix lane 2 builds it, with his credit in the Changeset.

Overlap checked: #11982, #11279, #11156, #11121 (#11982 changes BottomSheetSwitcher files, BottomSheet.tsx and BottomSheet.spec.md, none of which this changes; #11279 adds an empty-region option on the next line of the same Tab handler, independent behavior, so whichever merges second rebases one line; #11156 and #11121 change useFocusTrapInternal, not the region's Tab cycle)

User impact

A modal Dialog, BottomSheet, Lightbox or MobileNav with a roving group at its end (a radio group, a toolbar, a segmented control) let Tab escape. The group's other members hold tabindex="-1", as a roving group requires. The focus region still counted them as Tab stops, so Tab from the group's one real stop did not wrap. Focus left the sheet for the browser's own toolbar, and only the next Tab came back. Shift+Tab from the first stop also landed on a tabindex="-1" button. Now Tab from the last real stop wraps to the first, and Shift+Tab from the first wraps to the last.

Cause and fix

The region builds its Tab cycle from getFocusableElements, whose FOCUSABLE_SELECTOR keeps a button, a link or an input with tabindex="-1". Only its [tabindex] part excludes -1.

The region's Tab cycle, and its redirect when keyboard focus escapes, now drop every element with a negative tabindex. A negative tabindex takes any element out of the browser's Tab order. One isTabStop in hooks/focusableSelector.ts states that rule, and three of the places that walk Tab stops now share it: the focus region, Popover's initial focus (preferTabStops) and a menu's header and footer (tabbablesIn). Before, those two read tabindex !== "-1" and tabIndex >= 0, so a tabindex="-2" button was a stop for one and not the other. The shared getFocusableElements and FOCUSABLE_SELECTOR are unchanged, because SideNav and a trap's initial focus also read them. Other Tab-stop walks (the BottomSheet stack, scroll-keyboard delegation, the Toast viewport) keep their own tests; converting them is outside this fix. A tabindex="-1" element that holds focus programmatically (a dialog title) still decides the edge by its place in document order, as before.

Records

component:BottomSheet FR16 and component:Dialog FR7 (component:Dialog DEC-2, one focus-region module for every modal presentation): Tab from the last tabbable control moves focus to the first, and Shift+Tab from the first moves it to the last. A tabindex="-1" button is not tabbable, so the region now follows the records. No record change.

Evidence

  • Red first: on main, useFocusTrap.test.tsx "skips buttons with tabindex="-1" at either end of the Tab cycle" and BottomSheet.test.tsx "wraps past a roving group's tabindex="-1" buttons at the end of the sheet" (the issue's reproduction) fail. Both pass here.
  • focusableSelector.test.ts covers isTabStop: no tabindex, 0 and 2 are stops; -1 and -2 are not; a non-number value is a stop, as in the browser.
  • vitest run --project ui for useFocusTrap, focusableSelector, BottomSheet, Dialog, DropdownMenu (its header and footer stops included), Popover, SideNav and the shared focus-keyboard suite: 30 files, 1,214 of 1,215 tests pass. The one Menu a11y harness case that timed out under the parallel run passes alone, with its file and MenuButton's (2 files, 17 tests).

Scope

Components: the shared focus region (Dialog, BottomSheet, Lightbox, MobileNav)

  • One fix.
  • Test-backed, red first.
  • Public text contains no internal context.

…th a negative tabindex

A roving group's other members hold tabindex="-1", but FOCUSABLE_SELECTOR keeps a button or link with it, so the region took them as its first or last stop and Tab escaped the modal. The region's Tab cycle and its escape redirect now drop negative-tabindex elements; the shared getFocusableElements is unchanged. Fixes #11957, claimed and proposed by @jimmyallinai.
@vercel

vercel Bot commented Nov 17, 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 26, 2026 3:47pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 26, 2026, 4:34 PM UTC

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

Copy link
Copy Markdown
Contributor Author

/approve-spec a56d1bd

@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · a1e8e2d

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Markdown 211.3 kB (+77 B) · 23.8 kB CSS (0) — — · — · —
TableHeaderCell 112.0 kB (+76 B) · 20.3 kB CSS (0) — — · — · —
MobileNav 82.8 kB (+73 B) · 11.9 kB CSS (0) — — · — · —
141 more components
Component Size LoC Visual · A11y · RTL
Dialog 29.6 kB (+71 B) · 7.4 kB CSS (0) — — · — · —
TableCell 112.1 kB (+71 B) · 20.5 kB CSS (0) — — · — · —
AlertDialog 137.4 kB (+68 B) · 16.4 kB CSS (0) — — · — · —
ContextMenu 111.0 kB (+66 B) · 19.9 kB CSS (0) — — · — · —
BottomSheet 77.8 kB (+62 B) · 7.9 kB CSS (0) — ✓ · ✓ · —
DropdownMenu 138.1 kB (+59 B) · 20.1 kB CSS (0) — ✓ · ✓ · ✓
lab/CommentThread 384.7 kB (+59 B) · 2.4 kB CSS (0) — — · — · —
charts/Chart 268.5 kB (+58 B) · 516 B CSS (0) — — · — · —
SideNav 118.8 kB (+57 B) · 12.8 kB CSS (0) — — · — · —
CommandPalette 87.4 kB (+55 B) · 14.0 kB CSS (0) — — · — · —
SideNavHeading 92.4 kB (+54 B) · 12.7 kB CSS (0) — — · — · —
Table 126.8 kB (+52 B) · 21.5 kB CSS (0) — — · — · —
TimeInput 185.5 kB (+52 B) · 18.0 kB CSS (0) — — · — · —
MoreMenu 138.3 kB (+51 B) · 20.1 kB CSS (0) — — · — · —
lab/TransferListSelector 156.5 kB (+49 B) · 1.6 kB CSS (0) — — · — · —
ChatComposer 94.6 kB (+47 B) · 13.7 kB CSS (0) — — · — · —
TabMenu 88.4 kB (+47 B) · 12.6 kB CSS (0) — — · — · —
lab/Comments 391.7 kB (+47 B) · 2.5 kB CSS (0) — — · — · —
Drawer 61.2 kB (+46 B) · 9.1 kB CSS (0) — — · — · —
TopNavHeading 92.1 kB (+45 B) · 12.6 kB CSS (0) — — · — · —
Lightbox 154.8 kB (+44 B) · 12.4 kB CSS (0) — — · — · —
lab/MediaSeekButton 229.7 kB (+44 B) · 1.5 kB CSS (0) — — · — · —
lab/Tour 111.6 kB (+44 B) · 1.0 kB CSS (0) — — · — · —
lab/VideoPlayer 238.2 kB (+44 B) · 2.1 kB CSS (0) — — · — · —
Popover 109.5 kB (+43 B) · 15.8 kB CSS (0) — — · — · —
lab/MediaPlayButton 229.7 kB (+43 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaVolume 229.7 kB (+43 B) · 1.5 kB CSS (0) — — · — · —
MultiSelector 109.3 kB (+42 B) · 19.2 kB CSS (0) — — · — · —
PowerSearch 325.8 kB (+42 B) · 27.7 kB CSS (0) — — · — · —
charts/ChartTooltip 244.8 kB (+41 B) · 451 B CSS (0) — — · — · —
ContextMenuItem 42.5 kB (+41 B) · 7.4 kB CSS (0) — — · — · —
TopNavMenu 91.3 kB (+41 B) · 12.7 kB CSS (0) — — · — · —
lab/CommentComposer 192.0 kB (+41 B) · 1.9 kB CSS (0) — — · — · —
Pagination 154.8 kB (+40 B) · 20.3 kB CSS (0) — — · — · —
Tokenizer 118.0 kB (+40 B) · 22.2 kB CSS (0) — — · — · —
lab/MediaCaptionsButton 229.7 kB (+40 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaFullscreenButton 229.7 kB (+40 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaPlaybackRate 229.7 kB (+40 B) · 1.5 kB CSS (0) — — · — · —
lab/MediaTimeSlider 229.7 kB (+40 B) · 1.5 kB CSS (0) — — · — · —
SideNavItem 86.4 kB (+39 B) · 12.6 kB CSS (0) — — · — · —
lab/MediaTime 229.7 kB (+39 B) · 1.5 kB CSS (0) — — · — · —
ChatComposerTokenElement 91.7 kB (+37 B) · 12.7 kB CSS (0) — — · — · —
Typeahead 99.5 kB (+37 B) · 14.6 kB CSS (0) — — · — · —
ChatComposerInput 91.7 kB (+36 B) · 12.7 kB CSS (0) — — · — · —
BaseTypeahead 87.6 kB (+35 B) · 12.3 kB CSS (0) — — · — · —
ComplexSelector 87.4 kB (+35 B) · 13.5 kB CSS (0) — — · — · —
richtext/RichTextEditorToolbar 298.0 kB (+35 B) · 454 B CSS (0) — — · — · —
AppShell 94.5 kB (+33 B) · 15.1 kB CSS (0) — — · — · —
DateInput 213.6 kB (+33 B) · 19.2 kB CSS (0) — — · — · —
DateRangeInput 100.6 kB (+33 B) · 14.4 kB CSS (0) — — · — · —
TopNavMegaMenu 85.4 kB (+33 B) · 13.3 kB CSS (0) — — · — · —
Selector 121.6 kB (+32 B) · 20.0 kB CSS (0) — — · — · —
lab/ChatReactionBar 134.5 kB (+32 B) · 1.1 kB CSS (0) — — · — · —
Carousel 81.5 kB (+30 B) · 12.3 kB CSS (0) — — · — · —
DropdownMenuSubMenu 83.2 kB (+29 B) · 11.5 kB CSS (0) — ✓ · ✓ · ✓
lab/Schedule 122.4 kB (+27 B) · 3.9 kB CSS (0) — — · — · —
DateTimeInput 237.3 kB (+26 B) · 20.9 kB CSS (0) — — · — · —
lab/ChatEmojiPicker 133.0 kB (+26 B) · 773 B CSS (0) — — · — · —
TopNav 74.0 kB (+25 B) · 12.3 kB CSS (0) — — · — · —
MobileNavToggle 72.2 kB (+24 B) · 11.9 kB CSS (0) — — · — · —
lab/AudioPlayer 240.1 kB (+18 B) · 1.8 kB CSS (0) — — · — · —
BreadcrumbItem 107.0 kB (+17 B) · 14.3 kB CSS (0) — — · — · —
lab/TransferList 143.9 kB (+4 B) · 1.4 kB CSS (0) — — · — · —
Toast 110.1 kB (+2 B) · 11.6 kB CSS (0) — — · — · —
ChatToolCalls 33.8 kB (+1 B) · 9.2 kB CSS (0) — — · — · —
CheckboxList 78.6 kB (+1 B) · 8.5 kB CSS (0) — — · — · —
DialogHeader 73.3 kB (+1 B) · 13.0 kB CSS (0) — — · — · —
Heading 12.9 kB (+1 B) · 6.1 kB CSS (0) — — · — · —
NumberInput 109.2 kB (+1 B) · 13.2 kB CSS (0) — — · — · —
RadioListItem 81.4 kB (+1 B) · 11.6 kB CSS (0) — — · — · —
TableSelectionToolbar 80.7 kB (+1 B) · 14.7 kB CSS (0) — — · — · —
Text 12.1 kB (+1 B) · 6.1 kB CSS (0) — — · — · —
lab/LineClamp 14.7 kB (+1 B) · 168 B CSS (0) — — · — · —
lab/ListInput 100.7 kB (+1 B) · 1.3 kB CSS (0) — — · — · —
lab/TabBarMoreList 108.0 kB (+1 B) · 1.8 kB CSS (0) — — · — · —
richtext/RichTextView 290.3 kB (+1 B) · 2.4 kB CSS (0) — — · — · —
Avatar 48.6 kB (0) · 6.3 kB CSS (0) — — · — · —
AvatarGroup 51.4 kB (0) · 6.4 kB CSS (0) — — · — · —
AvatarGroupOverflow 54.6 kB (0) · 6.4 kB CSS (0) — — · — · —
Banner 72.1 kB (0) · 11.8 kB CSS (0) — — · — · —
BottomSheetSwitcher 20.0 kB (0) · 3.4 kB CSS (0) — ✓ · ✓ · —
ChatLayout 93.8 kB (0) · 11.8 kB CSS (0) — — · — · —
ChatMessageList 29.2 kB (0) · 7.8 kB CSS (0) — — · — · —
CheckboxInput 73.7 kB (0) · 11.0 kB CSS (0) — — · — · —
CheckboxListItem 85.4 kB (0) · 13.0 kB CSS (0) — — · — · —
CodeBlock 86.3 kB (0) · 13.0 kB CSS (0) — — · — · —
Collapsible 30.1 kB (0) · 4.6 kB CSS (0) — — · — · —
DropdownMenuCheckboxItem 30.3 kB (0) · 7.7 kB CSS (0) — ✓ · ✓ · ✓
DropdownMenuDivider 5.4 kB (0) · 548 B CSS (0) — ✓ · ✓ · —
DropdownMenuGroup 6.6 kB (0) · 3.4 kB CSS (0) — ✓ · ✓ · —
DropdownMenuItem 29.5 kB (0) · 7.2 kB CSS (0) — ✓ · ✓ · —
DropdownMenuRadioGroup 6.7 kB (0) · 3.4 kB CSS (0) — ✓ · ✓ · —
DropdownMenuRadioItem 30.3 kB (0) · 7.7 kB CSS (0) — ✓ · ✓ · —
FieldLabel 59.0 kB (0) · 6.5 kB CSS (0) — — · — · —
HoverCard 31.4 kB (0) · 4.8 kB CSS (0) — — · — · —
IconButton 70.0 kB (0) · 11.3 kB CSS (0) — — · — · —
InfoTip 53.7 kB (0) · 6.1 kB CSS (0) — — · — · —
InputGroup 65.7 kB (0) · 9.2 kB CSS (0) — — · — · —
LayoutPanel 22.4 kB (0) · 5.1 kB CSS (0) — — · — · —
Link 60.2 kB (0) · 7.8 kB CSS (0) — — · — · —
ListItem 84.5 kB (0) · 13.0 kB CSS (0) — — · — · —
NavHeadingMenuItem 20.1 kB (0) · 7.1 kB CSS (0) — — · — · —
ProgressBar 12.5 kB (0) · 7.0 kB CSS (0) — — · — · —
RadioList 65.1 kB (0) · 8.0 kB CSS (0) — — · — · —
ScrollableArea 11.7 kB (0) · 4.4 kB CSS (0) — — · — · —
SegmentedControl 105.5 kB (0) · 7.6 kB CSS (0) — — · — · —
Slider 119.5 kB (0) · 9.6 kB CSS (0) — — · — · —
StatusDot 36.6 kB (0) · 6.0 kB CSS (0) — — · — · —
Stepper 71.8 kB (0) · 11.4 kB CSS (0) — — · — · —
Switch 114.2 kB (0) · 10.9 kB CSS (0) — — · — · —
TabList 49.1 kB (0) · 6.8 kB CSS (0) — — · — · —
TextInput 103.9 kB (0) · 13.0 kB CSS (0) — — · — · —
Timer 14.6 kB (0) · 6.7 kB CSS (0) — — · — · —
ToggleButton 70.7 kB (0) · 11.3 kB CSS (0) — — · — · —
Toolbar 48.7 kB (0) · 8.6 kB CSS (0) — — · — · —
Tooltip 34.9 kB (0) · 5.1 kB CSS (0) — — · — · —
TreeList 47.9 kB (0) · 6.0 kB CSS (0) — — · — · —
lab/ChatVirtualizer 58.2 kB (0) · 223 B CSS (0) — — · — · —
lab/CommentPin 63.7 kB (0) · 1.2 kB CSS (0) — — · — · —
lab/DiffViewer 99.3 kB (0) · 2.3 kB CSS (0) — — · — · —
lab/EmojiPicker 123.8 kB (0) · 751 B CSS (0) — — · — · —
lab/NavigationScreen 87.0 kB (0) · 1.5 kB CSS (0) — — · — · —
lab/NavigationStack 87.0 kB (0) · 1.5 kB CSS (0) — — · — · —
Button 70.0 kB (−1 B) · 11.3 kB CSS (0) — — · — · —
Calendar 81.3 kB (−1 B) · 11.9 kB CSS (0) — — · — · —
ChatDictationButton 70.6 kB (−1 B) · 11.3 kB CSS (0) — — · — · —
ChatLayoutScrollButton 70.6 kB (−1 B) · 11.5 kB CSS (0) — — · — · —
ChatSendButton 70.5 kB (−1 B) · 11.3 kB CSS (0) — — · — · —
CommandPaletteInput 34.8 kB (−1 B) · 8.3 kB CSS (0) — — · — · —
FileInput 80.4 kB (−1 B) · 12.9 kB CSS (0) — — · — · —
Spinner 25.8 kB (−1 B) · 7.0 kB CSS (0) — — · — · —
TextArea 97.6 kB (−1 B) · 10.3 kB CSS (0) — — · — · —
lab/SelectableCardGroup 74.0 kB (−1 B) · 162 B CSS (0) — — · — · —
richtext/RichTextEditor 313.6 kB (−1 B) · 2.7 kB CSS (0) — — · — · —
DrawerHeader 73.5 kB (−2 B) · 14.4 kB CSS (0) — — · — · —
Field 63.6 kB (−2 B) · 8.0 kB CSS (0) — — · — · —
SideNavCollapseButton 70.9 kB (−2 B) · 11.4 kB CSS (0) — — · — · —
lab/DialogHeroHeader 94.8 kB (−2 B) · 372 B CSS (0) — — · — · —
Timestamp 28.5 kB (−3 B) · 11.5 kB CSS (0) — — · — · —
charts/ChartLegend 44.1 kB (−4 B) · 224 B CSS (0) — — · — · —
Thumbnail 74.8 kB (−4 B) · 12.8 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 8.09 MB packed (+410 B); 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 Tab-cycle fix itself is correct: both new tests fail on the base and pass here, and the wider focus, overlay and menu suites pass. Three things need fixing before approval:

  • packages/core/src/hooks/useFocusTrap.ts adds a private isTabStop beside the existing Tab-stop tests in preferTabStops (hooks/focusableSelector.ts) and tabbablesIn (DropdownMenu/menuRegionStops.ts), and the three disagree (a tabindex="-2" button is a Tab stop for Popover's initial focus but not for the focus region), so please export one isTabStop from focusableSelector.ts and call it from all three.
  • The description says no pull request came within 48 hours of the issue being claimed, but the claim on #11957 was posted 32 hours before this pull request opened, so please correct that sentence.
  • The overlap note says #11982 changes BottomSheetSwitcher files only, but it also edits BottomSheet.tsx and BottomSheet.spec.md (neither overlaps this pull request), so please correct it.
Claims and files checked

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

  • Claim: fixes the issue where Tab leaves a modal sheet past a roving group (verified: the new BottomSheet test fails on the base and passes here).
  • Claim: the issue's claimant proposed this fix (verified; he proposed filtering in the shared helper, this filters in the region, with the same outcome).
  • Claim: no pull request came within 48 hours of the claim (false: 32 hours had passed).
  • Claim: the changeset credits the claimant (verified).
  • Claim: #11982 changes switcher files only (false: it also edits BottomSheet.tsx and the BottomSheet record; no overlap with these files).
  • Claim: #11279 adds an independent option beside the same Tab handler (verified; the two heads merge cleanly).
  • Claim: #11156 and #11121 change the trap's options and focus return, not the region's Tab cycle (verified).
  • Claim: Dialog, BottomSheet, Lightbox and MobileNav let Tab escape past a roving group, and Shift+Tab landed on a tabindex="-1" button (verified for BottomSheet, Dialog and MobileNav by test; Lightbox through the same call).
  • Claim: the shared selector keeps a button, link or input with tabindex="-1" (verified in focusableSelector.ts).
  • Claim: the Tab cycle and the escape redirect now drop negative-tabindex elements (verified at useFocusTrap.ts:355-361 and :445).
  • Claim: getFocusableElements and FOCUSABLE_SELECTOR stay unchanged for DropdownMenu, SideNav and initial focus (verified).
  • Claim: a focused tabindex="-1" title still decides the edge by document order (verified at useFocusTrap.ts:476-493 and by the existing title tests).
  • Claim: the Dialog and BottomSheet Tab-wrap requirements govern, with no record change (verified).
  • Claim: red first, and the focus suites pass (verified: both new tests fail on the base; 268 test files and 7,896 tests pass here).
  • Claim: the public text carries no internal context (verified).
  • Changeset: a patch fix so Tab wraps both ways past tabindex="-1" buttons in Dialog, BottomSheet, Lightbox and MobileNav (verified; Drawer, Popover and the public useFocusTrap change too).
  • File .changeset/focus-region-negative-tabindex.md: clear.
  • File packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.
  • File packages/core/src/hooks/useFocusTrap.test.tsx: clear.
  • File packages/core/src/hooks/useFocusTrap.ts: duplicated Tab-stop test (first finding above).

Automated review (maintainer link)

Comment thread packages/core/src/hooks/useFocusTrap.ts Resolved
…l focus and a menu's header and footer

The three Tab-stop walks read a negative tabindex three ways (tabindex !== '-1', tabIndex >= 0, and the region's new test), so a tabindex="-2" button was a stop for one and not another. isTabStop in hooks/focusableSelector.ts states the rule once: any negative tabindex leaves the Tab order.
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec ea4f60d

@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 for one sentence in the description. The Tab-cycle fix and the shared isTabStop are correct: the three earlier findings are fixed, the new tests fail on the base and pass here, and the focus, overlay and menu suites pass.

  • The description says "the three places that walk Tab stops now share it", but BottomSheet/bottomSheetStack.ts (firstSequentiallyFocusable), hooks/scrollKeyboardDelegation.ts (isSequential) and Toast/ToastViewport.tsx (getFocusable, which still treats a tabindex="-2" button as a target) keep their own Tab-stop tests, so please reword it, for example to "three of the places that walk Tab stops now share it"; converting those callers is not needed here.
Claims and files checked

Review mode: incremental; reason: none

  • changed rules (0): none
  • Claim: fixes the issue where Tab leaves a modal sheet past a roving group (verified: the new BottomSheet test fails on the base and passes here; Chromium shows the same).
  • Claim: the issue's claimant claimed it on November 16 and proposed this fix (verified; he proposed filtering in the shared helper, this filters at the Tab-stop callers, with the same outcome).
  • Claim: no pull request followed the claim (verified: the claimant has opened none in this repository).
  • Claim: the changeset credits the claimant (verified).
  • Claim: #11982 changes switcher files, BottomSheet.tsx and the BottomSheet record, none of which this changes (verified; the two heads merge cleanly).
  • Claim: #11279 adds an independent empty-region option beside the same Tab handler (verified; the two heads merge cleanly).
  • Claim: #11156 and #11121 change the trap's internals, not the region's Tab cycle (verified).
  • Claim: Dialog, BottomSheet, Lightbox and MobileNav let Tab escape past a roving group, and Shift+Tab landed on a tabindex="-1" button (verified for BottomSheet in Chromium and by test, Dialog and MobileNav by test; Lightbox through the same call).
  • Claim: the shared selector keeps a button, link or input with tabindex="-1" (verified in focusableSelector.ts).
  • Claim: the Tab cycle and the escape redirect now drop negative-tabindex elements (verified in useFocusTrap.ts).
  • Claim: one isTabStop states the rule and the region, Popover's initial focus and a menu's header and footer share it (verified).
  • Claim: those are the three places that walk Tab stops (false: three other Tab-stop tests remain, see above).
  • Claim: before, a tabindex="-2" button was a stop for Popover's initial focus and not for a menu's header (verified from the replaced tests).
  • Claim: getFocusableElements and FOCUSABLE_SELECTOR stay unchanged for SideNav and a trap's initial focus (verified).
  • Claim: a focused tabindex="-1" title still decides the edge by document order (verified by the existing title tests).
  • Claim: the Dialog and BottomSheet Tab-wrap requirements govern, with no record change (verified).
  • Claim: red first (verified: the two behaviour tests and the three isTabStop tests fail on the base and pass here).
  • Claim: the new unit test covers no tabindex, 0, 2, -1, -2 and a non-number value (verified).
  • Claim: the focus suites pass (verified: a wider run of 243 test files passes here with no timeouts).
  • Claim: the public text carries no internal context (verified).
  • Changeset: a patch fix so Tab wraps both ways past tabindex="-1" buttons in Dialog, BottomSheet, Lightbox and MobileNav (verified; Drawer, Popover and the public useFocusTrap change too).
  • File .changeset/focus-region-negative-tabindex.md: clear.
  • File packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.
  • File packages/core/src/DropdownMenu/menuRegionStops.ts: clear.
  • File packages/core/src/hooks/focusableSelector.test.ts: clear.
  • File packages/core/src/hooks/focusableSelector.ts: clear.
  • File packages/core/src/hooks/useFocusTrap.test.tsx: clear.
  • File packages/core/src/hooks/useFocusTrap.ts: clear (the earlier duplicated Tab-stop test is gone).

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, because a draft pull request runs no CI; marking it ready for review starts the run. The Tab-cycle fix and the shared isTabStop are correct, the description's Tab-stop sentence is now accurate, and the new tests fail on the base and pass here.

Claims and files checked

Review mode: same-head; reason: none

  • changed rules (0): none
  • Claim: fixes the issue where Tab leaves a modal sheet past a roving group (verified: the new BottomSheet test fails on the base and passes here; a browser capture shows the same).
  • Claim: the issue's claimant claimed it on November 16 and proposed this fix (verified; he proposed filtering in the shared helper, this filters at the Tab-stop callers, with the same outcome).
  • Claim: no pull request followed the claim (verified: the claimant has opened none in this repository).
  • Claim: the changeset credits the claimant (verified).
  • Claim: #11982 changes switcher files, BottomSheet.tsx and the BottomSheet record, none of which this changes (verified).
  • Claim: #11279 adds an independent empty-region option beside the same Tab handler (verified; the two heads merge cleanly).
  • Claim: #11156 and #11121 change the trap's internals, not the region's Tab cycle (verified).
  • Claim: Dialog, BottomSheet, Lightbox and MobileNav let Tab escape past a roving group, and Shift+Tab landed on a tabindex="-1" button (verified by test and in a browser for BottomSheet; the others through the same module).
  • Claim: the shared selector keeps a button, link or input with tabindex="-1" (verified in focusableSelector.ts).
  • Claim: the Tab cycle and the escape redirect now drop every negative tabindex (verified in useFocusTrap.ts).
  • Claim: one isTabStop states the rule, and three of the places that walk Tab stops share it: the region, Popover's initial focus and a menu's header and footer (verified).
  • Claim: before, those two disagreed on a tabindex="-2" button (verified from the replaced lines).
  • Claim: getFocusableElements and FOCUSABLE_SELECTOR stay unchanged because SideNav and a trap's initial focus read them (verified).
  • Claim: the BottomSheet stack, scroll-keyboard delegation and the Toast viewport keep their own Tab-stop tests (verified).
  • Claim: a focused tabindex="-1" title still decides the edge by document order (verified by the existing title tests).
  • Claim: the Dialog and BottomSheet Tab-wrap requirements govern, with no record change (verified).
  • Claim: red first (verified: the two behaviour tests and the three isTabStop tests fail on the base and pass here).
  • Claim: the new unit test covers no tabindex, 0, 2, -1, -2 and a non-number value (verified).
  • Claim: the focus suites pass (verified: 58 test files and 1,669 tests across the trap, sheets, dialogs, menus and Popover pass here).
  • Claim: the public text carries no internal context (verified).
  • Changeset: a patch fix so Tab wraps both ways past tabindex="-1" buttons in Dialog, BottomSheet, Lightbox and MobileNav (verified; Drawer, Popover and the public useFocusTrap change too).
  • File .changeset/focus-region-negative-tabindex.md: clear.
  • File packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.
  • File packages/core/src/DropdownMenu/menuRegionStops.ts: clear.
  • File packages/core/src/hooks/focusableSelector.test.ts: clear.
  • File packages/core/src/hooks/focusableSelector.ts: clear.
  • File packages/core/src/hooks/useFocusTrap.test.tsx: clear.
  • File packages/core/src/hooks/useFocusTrap.ts: clear.

Automated review (maintainer link)

# Conflicts:
#	packages/core/src/hooks/focusableSelector.ts
#	packages/core/src/hooks/useFocusTrap.ts
@cixzhang
cixzhang marked this pull request as draft November 26, 2026 15:27
@cixzhang cixzhang added the ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) label Nov 26, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a1e8e2d

@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 UI test shards, typecheck and lint pass on this head, and the remaining CI jobs are still running. The Tab-cycle fix and the shared isTabStop are correct, and the new tests cover both ends of the cycle.

  • Regression (non-blocking): utils/focusReturn.ts on main has a private isTabStop and tabStopsIn with a tabIndex >= 0 rule, which differs from the shared one for a contenteditable or media control with no tabindex; routing them through the shared isTabStop, here or in a follow-up, keeps one rule.
Claims and files checked

Review mode: same-head; reason: none

  • changed rules (0)
  • Claim: fixes the linked issue where Tab leaves a modal sheet past a roving group (verified: the base Tab handler counts the group's tabindex="-1" buttons; the new BottomSheet test is the issue's reproduction and passes on this head).
  • Claim: the issue's claimant took it on November 16 and proposed this fix, and no pull request followed (verified on the issue and by search; he proposed filtering the shared helper, and this filters at the Tab-stop callers with the same outcome).
  • Claim: the changeset credits the claimant (verified).
  • Claim: #11982 changes switcher files, BottomSheet.tsx and the BottomSheet record, none of which this changes (verified; it has merged).
  • Claim: #11279 adds an independent empty-region option on the next line of the same Tab handler (verified from its patch).
  • Claim: #11156 and #11121 change the trap's internals, not the region's Tab cycle (verified; both have merged).
  • Claim: Dialog, BottomSheet, Lightbox and MobileNav let Tab escape past a roving group, and Shift+Tab landed on a tabindex="-1" button (verified from the base handler; all four call the region directly).
  • Claim: the shared selector keeps a button, link or input with tabindex="-1", and only its [tabindex] part excludes it (verified in focusableSelector.ts).
  • Claim: the Tab cycle and the escape redirect now drop every negative tabindex (verified in useFocusTrap.ts).
  • Claim: one isTabStop states the rule, and three places share it: the region, Popover's initial focus and a menu's header and footer (verified).
  • Claim: before, those two read !== "-1" and >= 0, so they disagreed on a tabindex="-2" button (verified from the replaced lines).
  • Claim: the shared helper and selector stay unchanged because SideNav and a trap's initial focus read them (verified).
  • Claim: the BottomSheet stack, scroll-keyboard delegation and the Toast viewport keep their own Tab-stop tests (verified; focus return's own tests, from main, are not listed, as the note above says).
  • Claim: a focused tabindex="-1" title still decides the edge by document order (verified: the programmatic-stop path is unchanged).
  • Claim: the Dialog and BottomSheet Tab-wrap requirements govern, with no record change (verified).
  • Claim: red first, both behaviour tests fail on main and pass here (verified by tracing both tests through the base handler; both pass in CI on this head).
  • Claim: the new unit test covers no tabindex, 0, 2, -1, -2 and a non-number value (verified).
  • Claim: the focus suites pass, with one parallel-run timeout passing alone (verified in substance: CI's four UI test shards pass on this head, the named suites included).
  • Claim: one fix, test-backed, and the public text carries no internal context (verified).
  • Changeset: a patch fix so Tab wraps both ways past tabindex="-1" buttons in Dialog, BottomSheet, Lightbox and MobileNav (verified; Drawer, Popover and the public useFocusTrap change too, which the changeset does not overstate).
  • File .changeset/focus-region-negative-tabindex.md: clear.
  • File packages/core/src/BottomSheet/BottomSheet.test.tsx: clear.
  • File packages/core/src/DropdownMenu/menuRegionStops.ts: clear.
  • File packages/core/src/hooks/focusableSelector.test.ts: clear.
  • File packages/core/src/hooks/focusableSelector.ts: non-blocking notes on focus return's separate rule and on a non-numeric tabindex.
  • File packages/core/src/hooks/useFocusTrap.test.tsx: clear.
  • File packages/core/src/hooks/useFocusTrap.ts: clear.

Automated review (maintainer link)

* other members hold `tabindex="-1"`. FOCUSABLE_SELECTOR keeps such a button
* or link, so callers that walk Tab stops filter with this.
*/
export function isTabStop(element: Element): boolean {

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.

Regression (non-blocking): utils/focusReturn.ts on main now has its own private isTabStop (tabIndex >= 0 && element.matches(FOCUSABLE_SELECTOR)) and tabStopsIn (tabIndex >= 0). They use a different rule from this one for a contenteditable or media control with no tabindex, which the browser tabs to. Having focus return call this export, element.matches(FOCUSABLE_SELECTOR) && isTabStop(element), keeps one rule. This can go here or in a follow-up.

@cixzhang
cixzhang marked this pull request as ready for review November 26, 2026 16:09
@cixzhang
cixzhang merged commit 8345a0a into main Nov 26, 2026
163 checks passed
@github-actions
github-actions Bot deleted the lane2/focus-region-tabindex branch November 27, 2026 06:04

This branch was successfully deployed

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

Labels

ci:run-a11y Run the accessibility suite on this PR; write access, next push (AST-030 FR12) CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] BottomSheet: Tab leaves a modal sheet when a button after the last stop has tabindex="-1"

1 participant