Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

ToggleGroup

Free6.4 KB gzipped

A set of toggle buttons (role="group", or role="toolbar") sharing one value. type="single" allows at most one pressed item (unpressing is allowed unless required); type="multiple" allows any number.

Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Tab, Arrow Right, Arrow Left and 6 more · Full report

Import

tsx
import { ToggleGroup, ToggleButton } from "@vjdesigns/vjdesigns-ui";

Importing only ToggleGroup adds about 6.4 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.

Examples

Single

type="single" allows one pressed item at a time.

tsx
import { useState } from "react";
import { ToggleGroup } from "@vjdesigns/vjdesigns-ui";

export function Single() {
  const [range, setRange] = useState<string | null>("30d");
  return (
    <ToggleGroup type="single" value={range} onValueChange={setRange} required variant="outline" tone="neutral" aria-label="Date range">
      <ToggleGroup.Item value="7d">7 days</ToggleGroup.Item>
      <ToggleGroup.Item value="30d">30 days</ToggleGroup.Item>
      <ToggleGroup.Item value="90d">90 days</ToggleGroup.Item>
    </ToggleGroup>
  );
}

Multiple

type="multiple" lets any number of items be pressed, like formatting buttons.

tsx
import { Stack, ToggleGroup } from "@vjdesigns/vjdesigns-ui";

export function Multiple() {
  return (
    <Stack gap={4} align="center">
      <ToggleGroup type="multiple" defaultValue={["bold"]} attached variant="soft" aria-label="Text formatting">
        <ToggleGroup.Item value="bold">Bold</ToggleGroup.Item>
        <ToggleGroup.Item value="italic">Italic</ToggleGroup.Item>
        <ToggleGroup.Item value="underline">Underline</ToggleGroup.Item>
      </ToggleGroup>
      <ToggleGroup type="multiple" defaultValue={["mon", "wed", "fri"]} checkmark variant="outline" aria-label="Workout days">
        <ToggleGroup.Item value="mon">Mon</ToggleGroup.Item>
        <ToggleGroup.Item value="tue">Tue</ToggleGroup.Item>
        <ToggleGroup.Item value="wed">Wed</ToggleGroup.Item>
        <ToggleGroup.Item value="thu">Thu</ToggleGroup.Item>
        <ToggleGroup.Item value="fri">Fri</ToggleGroup.Item>
      </ToggleGroup>
    </Stack>
  );
}

Single toggle

ToggleButton is a single on/off button with aria-pressed.

tsx
import { useState } from "react";
import { StarIcon, ToggleButton } from "@vjdesigns/vjdesigns-ui";

export function SingleToggle() {
  const [saved, setSaved] = useState(false);
  return (
    <ToggleButton pressed={saved} onPressedChange={setSaved} variant="outline" tone="warning" startIcon={<StarIcon />}>
      {saved ? "Saved" : "Save"}
    </ToggleButton>
  );
}

Accessibility

role="toolbar" with roving focus makes the group a single Tab stop; the arrow keys, Home and End move between buttons. Each item is a toggle button that reports its pressed state, and aria-label names the toolbar.

tsx
import { ToggleGroup } from "@vjdesigns/vjdesigns-ui";

export function Accessibility() {
  return (
    <ToggleGroup type="multiple" role="toolbar" aria-label="Text formatting" defaultValue={["bold"]} variant="outline" size="sm">
      <ToggleGroup.Item value="bold">Bold</ToggleGroup.Item>
      <ToggleGroup.Item value="italic">Italic</ToggleGroup.Item>
      <ToggleGroup.Item value="underline">Underline</ToggleGroup.Item>
    </ToggleGroup>
  );
}

Translated

Toggle buttons have no built-in words; the labels are your own text. LocaleProvider sets lang="zh-Hans" so screen readers read them in Chinese.

tsx
import { ToggleGroup, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import zhHans from "@vjdesigns/vjdesigns-ui/locales/zh-Hans";

export function Translated() {
  return (
    <LocaleProvider locale="zh-Hans" messages={zhHans}>
      <ToggleGroup type="single" aria-label="排序方式" defaultValue="new" variant="outline" size="sm">
        <ToggleGroup.Item value="new">最新</ToggleGroup.Item>
        <ToggleGroup.Item value="popular">最热门</ToggleGroup.Item>
        <ToggleGroup.Item value="price">价格</ToggleGroup.Item>
      </ToggleGroup>
    </LocaleProvider>
  );
}

Right to left

The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.

Single

tsx
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";

// Single is the "Single" example above.
<LocaleProvider locale="ar" messages={ar}>
  <Single />
</LocaleProvider>

Usage notes

Each item is a <button aria-pressed>, so this is for on/off options like text formatting or filter chips. For choosing exactly one of several mutually exclusive views, use SegmentedControl (a radio group) or Tabs.

Keyboard (with rovingFocus, the default): Tab enters and leaves the group at one item; Arrow keys move focus (wrapping); Home and End jump to the first and last item; Space and Enter toggle the focused item.

API reference

ToggleGroup

ToggleGroup props
PropTypeDefault
attached

Joins items edge to edge, sharing borders, with rounding on the outer corners only (like ButtonGroup attached).

booleanfalse
orientation

Layout direction. Also picks the arrow keys: Left/Right when horizontal, Up/Down when vertical.

"horizontal""vertical""horizontal"
gap

Space between items (a --space-* step). Ignored when attached.

Space2
rovingFocus

Toolbar-style roving tabindex: the group is one Tab stop, and Arrow keys, Home, and End move focus between items (wrapping). Turn off to make every item its own Tab stop. Inside a Toolbar it defaults to off, so the items join the toolbar's own arrow keys.

booleantrue (false inside a Toolbar)
role

ARIA role of the container. Use "toolbar" when the group is (or is the whole of) a formatting toolbar, such as Bold / Italic / Underline.

"group""toolbar""group"
required

Prevents unpressing the last pressed item: in single mode something is always selected; in multiple mode at least one item stays pressed.

booleanfalse
children

ToggleGroup.Item elements. Group style props are passed down; an item's own props win (except disabled, which either can set).

ReactNode—
variant

How the pressed state looks. Inherits from a surrounding ToggleGroup.

"solid""soft""outline""ghost""solid"
tone

Semantic color of the pressed state. Inherits from a surrounding ToggleGroup.

"neutral""primary""accent""success""warning""danger""info""primary"
size

Control height, padding, and type size. Inherits from a surrounding ToggleGroup.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --control-radius (pill). Inherits from a surrounding ToggleGroup.

"none""xs""sm""md""lg""xl""2xl""pill"—
disabled

Disables the control (native disabled). A disabled ToggleGroup disables every item.

booleanfalse
checkmark

Shows a check icon before the label while pressed, as an extra non-color cue. Not shown on icon-only buttons. Inherits from a surrounding ToggleGroup.

booleanfalse
fullWidth

Stretches the button to fill its container (in a group, items share the space equally).

booleanfalse
aria-label

Accessible name of the group. One of aria-label or aria-labelledby is required.

string—
aria-labelledby

Id of a visible element that names the group.

string—
typeRequired

single: at most one item pressed (value is a string or null). multiple: any number (value is a string array).

"single""multiple"—
value

Controlled value: the pressed item's value, or null for none.

string | null | string[]—
defaultValue

Initial value when uncontrolled.

string | null | string[]null
onValueChange

Called with the next value (null when the pressed item is unpressed).

(value: string | null) => void | (value: string[]) => void—

Also accepts standard HTML attributes, plus className, style and ref.

ToggleGroup.Item

One toggle in the group. See ToggleGroupItem.

ToggleGroup.Item props
PropTypeDefault
valueRequired

Value this item adds to (or sets as) the group's value when pressed. Must be unique in the group.

string—
variant

How the pressed state looks. Inherits from a surrounding ToggleGroup.

"solid""soft""outline""ghost""solid"
tone

Semantic color of the pressed state. Inherits from a surrounding ToggleGroup.

"neutral""primary""accent""success""warning""danger""info""primary"
size

Control height, padding, and type size. Inherits from a surrounding ToggleGroup.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --control-radius (pill). Inherits from a surrounding ToggleGroup.

"none""xs""sm""md""lg""xl""2xl""pill"—
disabled

Disables the control (native disabled). A disabled ToggleGroup disables every item.

booleanfalse
checkmark

Shows a check icon before the label while pressed, as an extra non-color cue. Not shown on icon-only buttons. Inherits from a surrounding ToggleGroup.

booleanfalse
fullWidth

Stretches the button to fill its container (in a group, items share the space equally).

booleanfalse
startIcon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
endIcon

Decorative icon (or count) after the label. Hidden from assistive technology.

ReactNode—
children

The visible label. Keep it the same whether pressed or not; aria-pressed announces the state.

ReactNode—
icon

Icon for icon-only mode. Use it instead of children, together with aria-label.

ReactNode—
aria-label

Defines a string value that labels the current element. Accessible name. Required in icon-only mode. Keep it constant (e.g. "Bold"), not "Bold on / Bold off".

string—

Also accepts standard HTML attributes, plus className, style and ref.

ToggleButton

A button that stays pressed or unpressed (<button type="button" aria-pressed>), for on/off options like Bold or "Show starters only". Pressed is shown by fill (or a tone border / indicator bar), a heavier label, and an optional check icon, never by color alone.

Inside a ToggleGroup, use ToggleGroup.Item instead so the group can manage selection and roving focus.

ToggleButton props
PropTypeDefault
pressed

Controlled pressed state.

boolean—
defaultPressed

Initial pressed state when uncontrolled.

booleanfalse
onPressedChange

Called with the next pressed state when the user toggles the button.

(pressed: boolean) => void—
variant

How the pressed state looks. Inherits from a surrounding ToggleGroup.

"solid""soft""outline""ghost""solid"
tone

Semantic color of the pressed state. Inherits from a surrounding ToggleGroup.

"neutral""primary""accent""success""warning""danger""info""primary"
size

Control height, padding, and type size. Inherits from a surrounding ToggleGroup.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --control-radius (pill). Inherits from a surrounding ToggleGroup.

"none""xs""sm""md""lg""xl""2xl""pill"—
disabled

Disables the control (native disabled). A disabled ToggleGroup disables every item.

booleanfalse
checkmark

Shows a check icon before the label while pressed, as an extra non-color cue. Not shown on icon-only buttons. Inherits from a surrounding ToggleGroup.

booleanfalse
fullWidth

Stretches the button to fill its container (in a group, items share the space equally).

booleanfalse
startIcon

Decorative icon before the label. Hidden from assistive technology.

ReactNode—
endIcon

Decorative icon (or count) after the label. Hidden from assistive technology.

ReactNode—
children

The visible label. Keep it the same whether pressed or not; aria-pressed announces the state.

ReactNode—
icon

Icon for icon-only mode. Use it instead of children, together with aria-label.

ReactNode—
aria-label

Defines a string value that labels the current element. Accessible name. Required in icon-only mode. Keep it constant (e.g. "Bold"), not "Bold on / Bold off".

string—

Also accepts standard HTML attributes, plus className, style and ref.

See what changed in each version in the Changelog.

Accessibility report

ToggleGroup targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.

axe-core audit (live)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Dark mode

Score 100

35 passed · 0 failed · 30 not applicable · 10 to check by hand

Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.

Built-in behavior

Keyboard

Keyboard
KeyAction
TabMoves into the group (one tab stop with rovingFocus, the default). Inside a Toolbar, rovingFocus defaults to off and the items join the toolbar's arrow keys.
Arrow RightArrow LeftHorizontal: next or previous button, wrapping (mirrored right to left).
Arrow DownArrow UpVertical: next or previous button, wrapping.
HomeEndFirst or last button.
EnterSpacePresses or releases the focused button.

Roles and states

Roles and states
ElementRoleStates and properties
Groupgroup (or toolbar)aria-label, aria-orientation (toolbar)
Item <button>buttonaria-pressed

Manual checks

Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck.2.1.1 (A), 2.1.2 (A)
FocusFocus moves in a logical order, is always visible, and isn't hidden behind sticky headers.2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA)
Screen readersNames, roles and states are announced correctly, and status changes are announced without moving focus.1.3.1 (A), 4.1.2 (A), 4.1.3 (AA)
ColorMeaning never depends on color alone; your own colors meet contrast in both modes.1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA)
Zoom and reflowAt 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed.1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA)
Pointer targetsClick and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap.2.5.8 (AA), 2.5.5 (AAA)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)