Forms
ToggleGroup
Free6.4 KB gzippedA 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
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.
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.
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.
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.
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.
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
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
| Prop | Type | Default |
|---|---|---|
attachedJoins items edge to edge, sharing borders, with rounding on the outer corners only (like | boolean | false |
orientationLayout direction. Also picks the arrow keys: Left/Right when horizontal, Up/Down when vertical. | "horizontal""vertical" | "horizontal" |
gapSpace between items (a | Space | 2 |
rovingFocusToolbar-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 | boolean | true (false inside a Toolbar) |
roleARIA role of the container. Use | "group""toolbar" | "group" |
requiredPrevents unpressing the last pressed item: in | boolean | false |
children
| ReactNode | — |
variantHow the pressed state looks. Inherits from a surrounding | "solid""soft""outline""ghost" | "solid" |
toneSemantic color of the pressed state. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
disabledDisables the control (native | boolean | false |
checkmarkShows a check icon before the label while pressed, as an extra non-color cue. Not shown on icon-only buttons. Inherits from a surrounding | boolean | false |
fullWidthStretches the button to fill its container (in a group, items share the space equally). | boolean | false |
aria-labelAccessible name of the group. One of | string | — |
aria-labelledbyId of a visible element that names the group. | string | — |
typeRequired
| "single""multiple" | — |
valueControlled value: the pressed item's value, or | string | null | string[] | — |
defaultValueInitial value when uncontrolled. | string | null | string[] | null |
onValueChangeCalled with the next value ( | (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.
| Prop | Type | Default |
|---|---|---|
valueRequiredValue this item adds to (or sets as) the group's value when pressed. Must be unique in the group. | string | — |
variantHow the pressed state looks. Inherits from a surrounding | "solid""soft""outline""ghost" | "solid" |
toneSemantic color of the pressed state. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
disabledDisables the control (native | boolean | false |
checkmarkShows a check icon before the label while pressed, as an extra non-color cue. Not shown on icon-only buttons. Inherits from a surrounding | boolean | false |
fullWidthStretches the button to fill its container (in a group, items share the space equally). | boolean | false |
startIconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon (or count) after the label. Hidden from assistive technology. | ReactNode | — |
childrenThe visible label. Keep it the same whether pressed or not; | ReactNode | — |
iconIcon for icon-only mode. Use it instead of | ReactNode | — |
aria-labelDefines 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.
| Prop | Type | Default |
|---|---|---|
pressedControlled pressed state. | boolean | — |
defaultPressedInitial pressed state when uncontrolled. | boolean | false |
onPressedChangeCalled with the next pressed state when the user toggles the button. | (pressed: boolean) => void | — |
variantHow the pressed state looks. Inherits from a surrounding | "solid""soft""outline""ghost" | "solid" |
toneSemantic color of the pressed state. Inherits from a surrounding | "neutral""primary""accent""success""warning""danger""info" | "primary" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
disabledDisables the control (native | boolean | false |
checkmarkShows a check icon before the label while pressed, as an extra non-color cue. Not shown on icon-only buttons. Inherits from a surrounding | boolean | false |
fullWidthStretches the button to fill its container (in a group, items share the space equally). | boolean | false |
startIconDecorative icon before the label. Hidden from assistive technology. | ReactNode | — |
endIconDecorative icon (or count) after the label. Hidden from assistive technology. | ReactNode | — |
childrenThe visible label. Keep it the same whether pressed or not; | ReactNode | — |
iconIcon for icon-only mode. Use it instead of | ReactNode | — |
aria-labelDefines 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)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 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
| Key | Action |
|---|---|
| Tab | Moves 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 Left | Horizontal: next or previous button, wrapping (mirrored right to left). |
| Arrow DownArrow Up | Vertical: next or previous button, wrapping. |
| HomeEnd | First or last button. |
| EnterSpace | Presses or releases the focused button. |
Roles and states
| Element | Role | States and properties |
|---|---|---|
| Group | group (or toolbar) | aria-label, aria-orientation (toolbar) |
Item <button> | button | aria-pressed |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every 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) |
| Focus | Focus 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 readers | Names, 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) |
| Color | Meaning 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 reflow | At 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 targets | Click 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) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |