Skip to content

ToggleButtonGroup: add roving tabindex + decide connected-vs-unconnected visual (relationship to ButtonGroup & SegmentedControl) #4238

Open

Description

@cixzhang

Summary

ToggleButtonGroup manages a set of toggle buttons (single/multiple select) but does not implement roving tabindex — so every toggle button is its own tab stop (the same keyboard a11y anti-pattern we're fixing elsewhere, e.g. AvatarGroup #4170). It should be a single tab stop with arrow-key navigation across its buttons. Fixing this cleanly runs into a design question about how it relates to ButtonGroup (connected visuals) and SegmentedControl (radio semantics), which this issue should settle.

Current state (grounded in source)

  • ToggleButtonGroup (packages/core/src/ToggleButton/ToggleButtonGroup.tsx): role="group" + aria-label, discriminated type: 'single' | 'multiple', orientation. No useListFocus, no roving tabindex → N tab stops. No connected/unconnected visual treatment.
  • ButtonGroup (packages/core/src/ButtonGroup/ButtonGroup.tsx): already does BOTH the connected visual ("shared borders, border-radius only on outer edges") AND roving via useListFocus. It's a generic button grouper, not toggle-state-aware.
  • SegmentedControl (packages/core/src/SegmentedControl/SegmentedControl.tsx): the radio-group model — role=radiogroup/radio, useListFocus({hasRovingTabIndex: true}), selection-follows-focus (APG radiogroup). Single-select, connected visual.

The tension

  1. ToggleButtonGroup needs roving tabindex (single tab stop) — this part is table stakes; reuse the shared useListFocus({hasRovingTabIndex}) primitive (as SegmentedControl/AvatarGroup/ButtonGroup do).
  2. The connected visual (shared borders / outer-edge radius) currently lives in ButtonGroup — but ButtonGroup also owns roving. So if you compose ToggleButtonGroup on top of ButtonGroup to get the visual, you get two roving layers fighting each other. Visual and focus-management are entangled in ButtonGroup today.

Design options (pick one — this issue decides)

Option A — decouple visual from behavior via a connected/unconnected variant.
Add a visual variant (e.g. variant: 'connected' | 'separate', or isAttached) to ButtonGroup/ToggleButtonGroup so the connected styling can be applied independently of who owns roving. Then ToggleButtonGroup owns its own roving (single/multiple aware) and opts into the connected visual without inheriting ButtonGroup's focus management. Likely requires extracting ButtonGroup's connected-styling into something reusable that doesn't also wire roving.

Option B — make ToggleButtonGroup more like SegmentedControl / RadioList.
For the single-select case, lean into radiogroup semantics + owned roving (SegmentedControl already is this — is single-select ToggleButtonGroup redundant with it?). Clarify the boundary: SegmentedControl = single-select segmented radios; ToggleButtonGroup = multi-select (and/or non-radio single) toggles. ToggleButtonGroup gets the same useListFocus roving, with role/selection semantics appropriate to single vs multiple (single → radiogroup-like; multiple → group of toggle buttons with arrow nav).

Considerations for either:

  • Roving must handle both type='single' and type='multiple' (multiple isn't a radiogroup — it's a toolbar-ish group of independent toggles; arrow-nav + roving still apply, but ARIA differs from radio).
  • Reuse useListFocus({hasRovingTabIndex}) and the existing connected-styling — don't reimplement either.
  • Avoid double-roving: exactly one layer owns the single tab stop.
  • Respect orientation (arrow axis) and disabled-skip, matching SegmentedControl.
  • Non-breaking where possible; if single-select ToggleButtonGroup overlaps SegmentedControl, document the intended boundary rather than silently duplicating.

Acceptance (post-design)

  • ToggleButtonGroup is a single tab stop with arrow/Home/End roving across its buttons (both single and multiple), via the shared primitive.
  • A decided answer on connected-vs-unconnected visuals (a variant that decouples styling from focus management, or a SegmentedControl-aligned model) — with the ButtonGroup/SegmentedControl boundary documented.
  • Correct ARIA per selection mode; disabled-skip; non-breaking default; spec reviewed before build.

Activity

  1. added
    enhancement
    component
    needs-scoping
    on Jul 23, 2026
  2. AKnassa commented on Aug 9, 2026

    @AKnassa
    Contributor

    One correction before this gets scoped: ButtonGroup doesn't own roving tabindex. It calls useListFocus without hasRovingTabIndex (ButtonGroup.tsx:173-176), so it writes no tabindex at all. Three Buttons is three tab stops, with arrow nav on top. So there's no "two roving layers" conflict to design around, just two arrow handlers, and ToggleButtonGroup needs its own roving either way.

    On the visual: Button.tsx:687-699 already keys the connected styling off useButtonGroup() alone, so nothing needs extracting. The catch is the container. ButtonGroup has no gap, ToggleButtonGroup has gap: --spacing-1, so a connected variant would also need to drop the gap, switch align-items, and decide what happens to pressable and elevation (both !buttonGroup && gated). Cheaper than Option A assumes, but not free.

    Two smaller notes. For Option B, the blockers are that radios don't deselect on re-click (ToggleButtonGroup.tsx:213) and APG selection-follows-focus would make arrows fire onChange. And isDisabled on a ToggleButton inside a group currently has no effect (ToggleButton.tsx:254), so disabled-skip has nothing to skip yet.

    Happy to put up the roving half if that's useful, it's built and tested against main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    componentenhancementneeds-scoping

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions