VisorVisor
ComponentsForm

Toggle Group

A group of toggle buttons where one or multiple can be active. Built on Radix UI with CVA variants.

Variants

Sizes

Outline Sizes

The outline track's corners are concentric at every size: the indicator's radius is the track radius minus the track's padding and border.

Multiple Selection

Option Rows

variant="option" draws each item as a full-width row you tap to pick: a lettered key on the left (A, B, C…, filled when picked), the label, and in a multiple group a check box on the right. There is no radio dot; the whole row is the target. The group keeps ToggleGroup's semantics: a single group is a radiogroup, a multiple group a group of pressed buttons, arrow keys move between rows and Space or Enter picks. Add shortcuts and the letters work as keys while focus is in the group.

Single Pick

Multiple Picks

Descriptions and a Round Mark

description on an item adds a second line under its label. On a single group, mark puts a round mark on the right of each row: clear at rest, filled with a check in the theme's key colour (--interactive-primary-bg) once the row is picked. A multiple group keeps its check box, and takes descriptions the same way. The label stays each row's accessible name and the description becomes its accessible description.

In Five Looks

The rows above in each look on the theme picked in the docs. The rows are solid on a plain page; only the two Photo looks, which turn glass on (see Glass), blur the photo behind them.

Today
Dark
Dark + Photo
Light
Light + Photo

Two Columns

columns={2} lays the rows out two up, for a longer list of short answers.

Installation

npx visor add toggle-group

This copies two files into your project:

  • components/ui/toggle-group/toggle-group.tsx — the component
  • components/ui/toggle-group/toggle-group.module.css — the styles

Usage

import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group/toggle-group';

<ToggleGroup type="single">
  <ToggleGroupItem value="a">A</ToggleGroupItem>
  <ToggleGroupItem value="b">B</ToggleGroupItem>
</ToggleGroup>

API Reference

ToggleGroupProps

PropTypeDefaultDescription
type*'single' | 'multiple'—Whether one or multiple items can be active at once.
variant'default' | 'outline' | 'option''default'Visual style variant of the toggle group. option draws full-width tap-to-pick rows with a lettered key and, in a multiple group, a check box.
size'xs' | 'sm' | 'md' | 'lg''md'Size of the toggle items. The option variant ignores it.
columns1 | 21Option variant only: 2 lays the rows out in a two-column grid.
shortcutsbooleanfalsePressing A, B, C… while focus is in the group picks the item at that position.
valuestring | string[]—Controlled active value(s).
onValueChange(value: string | string[]) => void—Callback when the active value changes.

Sub-components

ComponentElementPurpose
ToggleGroup<div>Root group container with variant/size context and optional sliding indicator
ToggleGroupItem<button>Individual toggle button inheriting variant and size from the group. In the option variant it renders the key, the label and optional description, and the check box (multiple) or the round mark (single with mark)

Accessibility

  • Built on @radix-ui/react-toggle-group. A single-select group has role="radiogroup" with role="radio" items and aria-checked; a multi-select group stays a group of aria-pressed buttons
  • Keyboard focus draws a solid --border-focus ring at --focus-ring-width, offset by --focus-ring-offset, on every item
  • Provide an aria-label on <ToggleGroup> to describe the purpose of the group (e.g., "Text formatting", "View mode")
  • Keyboard: Arrow keys navigate between items within the group; Space/Enter toggles the focused item
  • Option variant: the letter key, the check box and the round mark are aria-hidden, so each row is named by its label alone. A description is wired to the row with aria-describedby, after any id the caller passes. With shortcuts, a letter key (no modifier) picks and focuses the row at that position; a disabled row ignores it

Theming

A theme sets the group's look with the toggle-group keys, so no tokens go on the group itself: the outline track's fill, the selected option's fill and ink, the unselected ink, and the compact (xs) label size, option sides and corners. Every key falls back to what the group read before, so a theme that sets none of them renders as it always has. A compact group on a dark well, the selected option in a soft accent wash:

components:
  toggle-group:
    track-bg: "rgba(0, 0, 0, 0.65)"
    selected-bg: "rgba(44, 224, 230, 0.09)"
    selected-text: "#2ce0e6"
    unselected-text: "rgba(255, 255, 255, 0.46)"
    xs-font-size: 10px
    xs-padding-x: 11px
    xs-track-radius: 8px
    xs-item-radius: 6px

The option variant has its own option-* keys: the row's gap, height, padding, corners, fill (rest, hover and picked), picked ring, ink and type; the description line's ink and size; the letter key's size, corners, edge, ink and type; the picked key, check and round mark fill (option-mark-bg, option-mark-text, by default the theme's key colour); and the check box's size (the round mark's too), corners and edge. The defaults are Visor's tokens. The row's blur is not a key: it is the glass layer's control blur, so it shows only inside data-glass="on". Glass rows over a photo, in a dark theme:

components:
  toggle-group:
    option-min-height: 54px
    option-padding: 10px 18px 10px 13px
    option-radius: 12px
    option-bg: "rgba(255, 255, 255, 0.09)"
    option-hover-bg: "rgba(255, 255, 255, 0.13)"
    option-selected-bg: "rgba(255, 255, 255, 0.2)"
    option-selected-ring: "rgba(255, 255, 255, 0.4)"
    option-description-text: "rgba(255, 255, 255, 0.64)"
    option-font-size: 17px
    option-key-radius: 8px
    option-mark-bg: "#e8457c"
    option-mark-text: "#ffffff"
    option-check-radius: 6px

The full list, with each fallback, is in Component Tokens.

Label Centering

The label is optically centred in any font: its line box is trimmed to the capital-height band, so capitals (not the font's ascent and descent) sit on the box centre, with the box size unchanged. Firefox keeps the previous rendering. Shared spec: docs/label-centering.md.