Skip to content

fix(ButtonGroup): one roving tab stop across the group's members - #5389

Merged
cixzhang merged 2 commits into
mainfrom
buttongroup-roving
Aug 24, 2026
Merged

cixzhang merged 2 commits into
mainfrom
buttongroup-roving

Conversation

@cixzhang

@cixzhang cixzhang commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

What changed

ButtonGroup now asks useListFocus for hasRovingTabIndex, so the group is a
single 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 is
load-bearing.

Line Change
ButtonGroup.tsx:191 hasRovingTabIndex: true
ButtonGroup.tsx:182 itemSelector: 'button, a[href], [tabindex]'
ButtonGroup.tsx:219 onFocus={composeEventHandlers(onFocus, handleFocus)}

The selector had to change with it. 'button, [tabindex="0"]' cannot survive
roving: 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 stop
moves. Toolbar matches on [tabindex] for exactly this reason
(Toolbar.tsx:247). The a[href] half is a defect the roving work surfaced: a
Button with href renders an <a> (Button.tsx:609), which button never
matched, so a link member was a stray tab stop that the arrow keys skipped over.
Both measured below.

onFocus keeps the stop honest after a click or a programmatic focus, which
is what useListFocus asks its roving consumers to attach. Same wiring as
AvatarGroup.tsx:151.

The container role stays group

I kept role="group" deliberately, rather than moving to role="toolbar".

  • This repo already has the toolbar. Toolbar is role="toolbar" with
    hasRovingTabIndex (Toolbar.tsx:246-251), and a ButtonGroup is a normal
    thing to put inside one. APG's toolbar pattern uses role="group" for the
    subdivisions of a toolbar, so group is the right role for a component whose
    own docs say "for more actions, use a Toolbar". Making this a toolbar would
    produce nested toolbars in a composition the docs recommend.
  • Roving is not the toolbar role's property. AvatarGroup is role="group"
    with hasRovingTabIndex: true today (AvatarGroup.tsx:123-147), so the
    precedent for this exact pairing is already in core.
  • aria-disabled on the container is meaningful on group and is what the
    isDisabled prop renders.
  • The boundary selector added in #5355 is keyed on [role="group"]
    (ButtonGroup.tsx:189). Changing the role silently unmatches the group's own
    root 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:build output over plain HTTP, driven with Playwright. Two
builds from the same tree with only ButtonGroup.tsx differing: 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.

parent 78e8e1c this PR
Tab walk before, Copy, Cut, Paste, after before, Copy, after
tabindex on the members none, none, none 0, -1, -1
link member (Save, Docs-as-<a>, Print) before, Save, Docs, Print, after before, Save, after
whole group isDisabled before, after before, after

Three 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

Story Keys Result
horizontal Right, Right, Right Cut, Paste, Copy (wraps)
horizontal Left Paste
horizontal End, Home Paste, Copy
horizontal Down no move (axis respected)
vertical Down, Down, Down Cut, Paste, Copy (wraps)
vertical Up Paste
vertical Right no move
horizontal, dir="rtl" Left, Left, Right Cut, Paste, Cut
vertical, dir="rtl" Down, Up Cut, Copy (unflipped, correct)

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

Group Tab stop lands on Arrows
Copy, Cut, Paste Copy (0, -1, -1) Copy, Right, Paste
Undo, Redo, Repeat Redo (-1, 0, -1) Redo, Left, Repeat (wraps past Undo); Home, Redo
Bold, Italic, Underline Bold (0, -1, -1) Italic, Right, Bold (wraps past Underline); End, Italic

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

ButtonGroup with a Button and a DropdownMenu
(#2508 composition):

Key Focus
Tab Allow once (tabindex=0; the trigger is -1)
ArrowRight Allow options trigger
Enter menuitem "Allow for 30 minutes"
ArrowDown menuitem "Always allow"
ArrowRight menuitem "Always allow" (menu keeps the key)
Escape Allow options trigger
ArrowLeft Allow once

The trigger participates in roving, the open menu owns the arrows, and Escape
comes back to the trigger. The group never stamps tabindex on the menu's own
items, 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 boundary
still matches the group's own root because the role did not change.

Where the stop starts, and what moves it

  • It starts on the first enabled member and follows arrow navigation.
  • Entering backwards (Shift+Tab from after the group) lands on the stop, not on
    the last member. Standard roving.
  • A member unmounting while focused: focus goes to <body> (unchanged from the
    parent 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.
  • A member becoming disabled while holding the stop: repaired the same way.

The focus ring

Captured at deviceScaleFactor: 3, clipped to the group, with focus arrived at
by 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 tabindex moved.

ArrowRight (LTR) ArrowLeft (RTL)
ltr rtl
ArrowDown (vertical) ArrowRight past a disabled member
vertical disabled
A member's open menu The group inside a Popover
menu popover

Tests

ButtonGroup.test.tsx gains a roving tabindex describe (9 tests) plus one
arrow-order test for the link member. Nine of the ten are red against the
parent commit
and green here, verified by swapping ButtonGroup.tsx in 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 of ButtonGroup is
wrong: it says ButtonGroup "already does BOTH the connected visual AND roving
via useListFocus". It did not. It called the hook without
hasRovingTabIndex, wrote no tabindex at all, and measured three tab stops
for 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 ToggleButtonGroup on top of ButtonGroup would give "two roving
layers fighting". That was hypothetical before and is now literal: ButtonGroup
owns 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 stop
for the whole toolbar, and one focus move per arrow press, because the group
preventDefaults and Toolbar bails on defaultPrevented
(Toolbar.tsx:261-268). ToggleButtonGroup does not compose ButtonGroup
today, 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/core is published, so I checked whether this warrants
[breaking] (which is the minor bump while 0.x). The wiki's breaking tier is
API 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 tooltip is no longer reachable by keyboard.
Button deliberately uses aria-disabled instead of disabled when a disabled
button 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 arrows
skip it (useListFocus treats aria-disabled="true" as disabled), so it cannot
be reached at all. This is the repo's settled position rather than a slip:
SegmentedControl removed the tab stop from disabled segments on purpose, and
every roving consumer shares the same isItemDisabled. But APG's toolbar
guidance 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 shared
syncTabStops, which keeps the current tabbable item when it is still enabled;
Toolbar, TabList and AvatarGroup all behave the same way. APG would have
the stop follow the click. A hook-level question, not a ButtonGroup one.

No keyboard hint. AvatarGroup pairs roving with a screen-reader hint via
aria-describedby, and Toolbar uses the visible useKeyboardHint badge.
ButtonGroup has neither. The visible badge would render a [popover] inside the
group 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 build and pnpm lint:strict clean. pnpm vitest run over ButtonGroup,
the whole hooks directory, and every other useListFocus consumer
(AvatarGroup, Breadcrumbs, ContextMenu, DropdownMenu, NavMenu,
Outline, Pagination, SegmentedControl, SideNav, TabList, TabMenu,
TopNav, Toolbar), plus Button, ToggleButton, Popover, Toast and
HoverCard for the layer and member sides: 1277 tests over 48 files, all
green
. check:sync, check:changesets and check:use-client pass in the
pre-commit gate.

Night Watch — Component Auditor

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.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Aug 24, 2026
@vercel

vercel Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview Aug 24, 2026 3:36am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

ButtonGroup (@astryxdesign/core) · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 125 -
Complexity N/A Low (3) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.8KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

github-actions Bot added a commit that referenced this pull request Aug 24, 2026
@cixzhang
cixzhang enabled auto-merge (squash) August 24, 2026 05:03
@cixzhang
cixzhang merged commit 917cc10 into main Aug 24, 2026
26 of 28 checks passed
@github-actions
github-actions Bot deleted the buttongroup-roving branch August 24, 2026 06:17
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

1 active deployment
Preview — 27e2cd69 Deployed Aug 24, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant