Repository navigation
fix(ButtonGroup): one roving tab stop across the group's members - #5389
Merged
Merged
Conversation
The group wired useListFocus for arrow keys but never asked for hasRovingTabIndex, so every member stayed in the tab order: three buttons were three tab stops, which is the composite-widget anti-pattern the APG roving tabindex technique exists to fix. Turns the hook's own option on rather than hand-rolling tab-stop management. The itemSelector has to change with it: '[tabindex="0"]' cannot survive roving, which stamps -1 on every member but one, and a Button rendered with href is an <a> that the 'button' half never matched, so a link member was both a stray tab stop and invisible to the arrow keys. role="group" is kept, so the boundarySelector added in #5355 still matches the group's own root.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsButtonGroup (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
cixzhang
enabled auto-merge (squash)
August 24, 2026 05:03
4 tasks done
cixzhang
pushed a commit
that referenced
this pull request
Oct 31, 2026
<!-- template: bug-fix.md --> ## User impact A builder who puts a link in a Toolbar, for example `<Button label="Docs" href="/docs" />` between Cut and Paste, gets a row with two Tab stops. Keyboard users have to Tab through the link on their way out of the toolbar, and the arrow keys jump over it, so the link is reachable only with Tab. ## Problem and solution fit - Why does it happen? Toolbar's roving `itemSelector` is `'button, input, [tabindex]'`. A Button with `href` renders an `<a href>` with no `tabindex`, so the selector never matches it. Roving neither stamps it `-1` nor visits it with the arrow keys, and the browser keeps it in the tab order. - Why does it hurt? The toolbar stops being one composite widget: Tab lands inside it twice, and the arrow-key order a screen-reader user learns skips one of its controls. - Why does it matter? `component:Toolbar` FR4 requires the row to be a single tab stop, and the APG toolbar pattern makes the toolbar one tab stop. Fix: add `a[href]` to the selector, the same change #5389 made in ButtonGroup for the same defect. ## Expected behavior and authority - `component:Toolbar` FR4 (authority `current`): "The row MUST be a single tab stop." The record listed links under its implementation gap; this change takes them out. - [WAI-ARIA APG toolbar pattern](https://www.w3.org/WAI/ARIA/apg/patterns/toolbar/). - Same-class precedent: #5389, which added `a[href]` to ButtonGroup's selector and called the missing link member a defect. ## Smallest restoration - `Toolbar.tsx`: `itemSelector` becomes `'button, input, a[href], [tabindex]'`. - `Toolbar.test.tsx`: one case. Tab from the first control leaves the toolbar, and ArrowRight visits the link. - `Toolbar.spec.md`: the FR4 implementation gap, the Current-state impact bullet, and the unverified list no longer name links. `textarea` and `select` stay in the gap: they use the arrow keys themselves, so they are not part of this fix. - A patch changeset. ## Evidence Playwright Chromium against Storybook served locally from this branch, with the selector reverted for AS-IS. The probe story (not committed) renders `Before`, a Toolbar with `Cut`, `Docs` (Button with `href`), and `Paste`, then `After`. Each caption is the focused element's role and name, read from Chromium's accessibility tree at that moment. The red outline and the caption panel are recording-only. | Key | `main` | This branch | | --- | --- | --- | | Tab from `Before` | button "Cut" | button "Cut" | | Tab | link "Docs" | button "After" | | ArrowRight from `Cut` | button "Paste" | link "Docs" | | ArrowRight | button "Cut" | button "Paste" | - Reproduction before the change: Tab stops on the link inside the toolbar, and the arrow keys skip it. - Result after the change: Tab leaves the toolbar from its single stop, and the arrow keys visit the link. - Representative unchanged path: rows of buttons and inputs only; the existing keyboard suites pass unchanged. - Regression test: the new case fails with `Toolbar.tsx` reverted to `main` (Tab from Cut lands on the link) and passes with this change. ### AS-IS https://github.com/user-attachments/assets/2c976bb4-1983-49c7-b2ca-521211e84b93 ### TO-BE https://github.com/user-attachments/assets/0a367db3-13ca-42ef-992f-8f4e2971d15e ## Writing rubric results - R1 narration: none; the edited sentences state which controls share the stop. - R2 research: none. - R3 evidence: no pull request is cited in the record. - R4 rejected alternatives: none. - R5 change references: none. - R6 open questions: none in the record. ## Scope - [x] One defect is restored. - [x] Separable contradictory or unsettled tagalongs were removed or split. - [x] No new public API, visual representation, default, or interaction model is hidden under the bug-fix label. - [x] Public text and artifacts contain no internal Meta context. ## Testing - `pnpm exec vitest run --project ui packages/core/src/Toolbar packages/core/src/ButtonGroup`: 88 passed. - `pnpm -F @astryxdesign/core typecheck`, eslint and prettier on the changed files, `pnpm check:knowledge`, `git diff --check`: passed. - Playwright Chromium keyboard walk of the cases above, `main` selector versus this branch.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
ButtonGroupnow asksuseListFocusforhasRovingTabIndex, so the group is asingle tab stop with arrow-key navigation rather than one tab stop per member.
Three lines, all in
packages/core/src/ButtonGroup/ButtonGroup.tsx, and each isload-bearing.
ButtonGroup.tsx:191hasRovingTabIndex: trueButtonGroup.tsx:182itemSelector: 'button, a[href], [tabindex]'ButtonGroup.tsx:219onFocus={composeEventHandlers(onFocus, handleFocus)}The selector had to change with it.
'button, [tabindex="0"]'cannot surviveroving: the hook stamps
tabindex="-1"on every member but one, so anything the[tabindex="0"]half was carrying drops out of its own list the moment the stopmoves.
Toolbarmatches on[tabindex]for exactly this reason(
Toolbar.tsx:247). Thea[href]half is a defect the roving work surfaced: aButtonwithhrefrenders an<a>(Button.tsx:609), whichbuttonnevermatched, so a link member was a stray tab stop that the arrow keys skipped over.
Both measured below.
onFocuskeeps the stop honest after a click or a programmatic focus, whichis what
useListFocusasks its roving consumers to attach. Same wiring asAvatarGroup.tsx:151.The container role stays
groupI kept
role="group"deliberately, rather than moving torole="toolbar".Toolbarisrole="toolbar"withhasRovingTabIndex(Toolbar.tsx:246-251), and a ButtonGroup is a normalthing to put inside one. APG's toolbar pattern uses
role="group"for thesubdivisions of a toolbar, so
groupis the right role for a component whoseown docs say "for more actions, use a Toolbar". Making this a toolbar would
produce nested toolbars in a composition the docs recommend.
AvatarGroupisrole="group"with
hasRovingTabIndex: truetoday (AvatarGroup.tsx:123-147), so theprecedent for this exact pairing is already in core.
aria-disabledon the container is meaningful ongroupand is what theisDisabledprop renders.[role="group"](
ButtonGroup.tsx:189). Changing the role silently unmatches the group's ownroot and reintroduces that regression, so a role change is not a one-line
change; it is a role change plus a selector change plus re-verification of
both layer behaviours. That is a reason to do it deliberately, not a reason to
avoid it, but combined with the three points above it is not what I would
spend the blast radius on. Left in Needs review, tied to
#4238.
Measured in Chromium
Static
storybook:buildoutput over plain HTTP, driven with Playwright. Twobuilds from the same tree with only
ButtonGroup.tsxdiffering:78e8e1c(parent) and this branch. Every row below is a real key press against real
Chromium, not jsdom.
Tab stops, before and after
A group of three buttons bracketed by a plain button on each side. Values are
the focused element after each Tab.
78e8e1ctabindexon the members<a>, Print)isDisabledThree tab stops become one. A four-member group with a link member went from
three stops plus a stray anchor to one.
Arrow keys, both axes and both directions
dir="rtl"dir="rtl"RTL flips the horizontal axis and leaves the vertical axis alone. Home and End
stay first/last in DOM order in both directions. Identical to the parent build,
which is the point: this PR moves the tab stop, it does not touch the arrow
semantics.
Disabled members
Cut, Paste0, -1, -1)Undo, Redo, Repeat-1, 0, -1)Underline0, -1, -1)The stop is never parked on a disabled member, at either end or in the middle,
and arrows skip them.
A member that owns a layer
ButtonGroupwith aButtonand aDropdownMenu(#2508 composition):
Allow once(tabindex=0; the trigger is-1)Allow optionstriggermenuitem "Allow for 30 minutes"menuitem "Always allow"menuitem "Always allow"(menu keeps the key)Allow optionstriggerAllow onceThe trigger participates in roving, the open menu owns the arrows, and Escape
comes back to the trigger. The group never stamps
tabindexon the menu's ownitems, which the boundary is what guarantees.
A group inside a Popover
The case #5355 fixed, re-verified: focus Copy, then ArrowRight, End,
Home gives Cut, Paste, Copy, and the members carry
0, -1, -1. The boundarystill matches the group's own root because the role did not change.
Where the stop starts, and what moves it
the last member. Standard roving.
<body>(unchanged from theparent build; the hook does not move focus) and the stop is repaired onto the
first enabled member on the same commit, so the next Tab re-enters correctly.
The focus ring
Captured at
deviceScaleFactor: 3, clipped to the group, with focus arrived atby key press rather than by script, so the ring is the one a user sees. Every
capture is pixel-identical to the parent build: only
tabindexmoved.Tests
ButtonGroup.test.tsxgains aroving tabindexdescribe (9 tests) plus onearrow-order test for the link member. Nine of the ten are red against the
parent commit and green here, verified by swapping
ButtonGroup.tsxin place:one tab stop on the first member, one Tab in and one Tab out, the stop moving
with the arrows, never parking on a disabled member, repair on unmount, repair
on disable, a link member counted as the tab stop, and a member's open menu not
being handed the group's stop. The tenth (a fully disabled group contributes no
tab stop) passes both ways and is a guard.
No existing test had to change. The three-tab-stop assumption was not baked
into this suite or any other: all 36 pre-existing ButtonGroup tests pass
untouched, including the two boundary tests from
#5355.
#4238
That issue is about
ToggleButtonGroup, and its account ofButtonGroupiswrong: it says ButtonGroup "already does BOTH the connected visual AND roving
via
useListFocus". It did not. It called the hook withouthasRovingTabIndex, wrote notabindexat all, and measured three tab stopsfor three buttons (the parent column above). This PR makes that claim true,
and I am leaving the issue open for @cixzhang rather than rewriting a design
issue's framing from a code PR.
There is a real concern underneath the wrong premise, and it is worth stating
precisely because it changes as of this PR. The issue's Option A worries that
composing
ToggleButtonGroupon top ofButtonGroupwould give "two rovinglayers fighting". That was hypothetical before and is now literal:
ButtonGroupowns a tab stop, so anything that wraps it and also owns one has to decide who
wins. I measured the one composition of that shape that exists today, a
ButtonGroup inside a
Toolbar, and it is benign in both builds: one tab stopfor the whole toolbar, and one focus move per arrow press, because the group
preventDefaults andToolbarbails ondefaultPrevented(
Toolbar.tsx:261-268).ToggleButtonGroupdoes not composeButtonGrouptoday, so nothing regresses; whoever picks up #4238 now has to design against a
ButtonGroup that really does own a tab stop.
Release rules
patch, category[fix], per Release-Process.@astryxdesign/coreis published, so I checked whether this warrants[breaking](which is the minor bump while 0.x). The wiki's breaking tier isAPI migration: prop or component renamed or removed, callback signature changed,
import path changed, and every row of the "what needs a codemod" table is a
codemod row. This changes no API and there is nothing to codemod. The repo's own
precedent for this exact change is consistent: TabList becoming a single tab
stop shipped under New Features, Outline's roving conversion under Other
Changes, and AvatarGroup's roving (#4170) under New Features. None were
[breaking].It is still a behaviour change on published surface, so the changeset says so in
the consumer's terms: a keyboard script or test that tabbed through a group
member by member has to use arrow keys now, and a link member joins the arrow
order.
Needs review
A disabled member with a
tooltipis no longer reachable by keyboard.Buttondeliberately usesaria-disabledinstead ofdisabledwhen a disabledbutton carries a tooltip, precisely so a keyboard user can still reach it and
read why it is disabled (
Button.tsx:610-611). Measured on the parent build,that member is a tab stop; measured here, it is
tabindex="-1"and the arrowsskip it (
useListFocustreatsaria-disabled="true"as disabled), so it cannotbe reached at all. This is the repo's settled position rather than a slip:
SegmentedControlremoved the tab stop from disabled segments on purpose, andevery roving consumer shares the same
isItemDisabled. But APG's toolbarguidance is the other way, and the fix would be a new option on the shared hook
affecting 14 consumers, which is not this PR. Flagging it as the one real cost
of this change.
Clicking a member does not move the tab stop. After clicking the third
member, the stop stays on the first, so Shift+Tab from there re-enters the group
at the first member instead of leaving. That is
useListFocus's sharedsyncTabStops, which keeps the current tabbable item when it is still enabled;Toolbar,TabListandAvatarGroupall behave the same way. APG would havethe stop follow the click. A hook-level question, not a ButtonGroup one.
No keyboard hint.
AvatarGrouppairs roving with a screen-reader hint viaaria-describedby, andToolbaruses the visibleuseKeyboardHintbadge.ButtonGroup has neither. The visible badge would render a
[popover]inside thegroup and is a visual change; the screen-reader hint needs a new i18n key. Both
are follow-ups rather than parts of this diff.
The role question is above, and belongs to #4238.
Checks
pnpm buildandpnpm lint:strictclean.pnpm vitest runover ButtonGroup,the whole
hooksdirectory, and every otheruseListFocusconsumer(
AvatarGroup,Breadcrumbs,ContextMenu,DropdownMenu,NavMenu,Outline,Pagination,SegmentedControl,SideNav,TabList,TabMenu,TopNav,Toolbar), plusButton,ToggleButton,Popover,ToastandHoverCardfor the layer and member sides: 1277 tests over 48 files, allgreen.
check:sync,check:changesetsandcheck:use-clientpass in thepre-commit gate.
Night Watch — Component Auditor