Toggle Group

Grouped toggle buttons with a clearable string[] selection model. Prefer Content Switcher for exclusive view modes as segments.

Also known as: button group, option group, toggle buttons, multi select toggles

Installation

Install with the CLI, or copy the component source into your project.

Add toggle-group (npm)

npx --yes -p @default-file/ui df-ui add toggle-group

Default

Single-select group.

Variants

Default and outline styles.

Sizes

Small, default, and large.

Orientation

Lay items out horizontally or vertically.

Radius

Adjust corner rounding from a full pill to a tighter square.

Multiple

Press more than one item at a time.

Properties

Grouped toggle buttons with a shared string[] value. Single-select is clearable: pressing the selected item clears the selection. Multi-select adds and removes values. Prefer Content Switcher for exclusive view modes as radio segments, and Switch for a single binary setting.

ToggleGroup

PropTypeDefaultNotes
variant"default" | "outline""default"Visual style for items.
size"default" | "sm" | "lg""default"Item height and type size.
radius"xxs" | "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "full"-Corner radius of the group. Defaults to a pill look.
cornerShape"round" | "smooth"-Instance corner curve. Omit to inherit --df-corner-shape from the theme (set at create/init).
spacingnumber2Gap between items (design-scale units).
orientation"horizontal" | "vertical""horizontal"Layout direction. Also sets the roving tabindex arrow-key axis.
multiplebooleanfalseWhen false, at most one value is selected and pressing the selected item clears to []. When true, values accumulate and each press toggles membership.
valuestring[]-Controlled selected values. Always an array, including single-select.
defaultValuestring[][]Uncontrolled initial values.
onValueChange(value: string[]) => void-Called when selection changes.
disabledbooleanfalseDisable the whole group.

ToggleGroupItem

PropTypeDefaultNotes
valuestring-Item value (required).
variant"default" | "outline"-Override group variant for this item.
size"default" | "sm" | "lg"-Override group size for this item.
disabledboolean-Non-interactive item.
childrenReactNode-Item label or icon.

Keyboard and accessibility

Selection (toggle button): Each item is a button with aria-pressed reflecting selection. Single and multi modes use the same pressed model, not radio or checkbox roles. Roving tabindex (Arrow keys): Arrow keys move focus along orientation. Home and End jump to the first and last enabled item. Space and Enter activate the focused item.

Tokens

Theme defaults live on :root. Override these globally or on a local host.

TokenTypeDefaultNotes
--df-toggle-radiusCSS lengthvar(--radius-4xl)Instance variable set from the radius prop. Falls back to --radius-4xl.
--gapCSS lengthcalc(2 * var(--spacing-unit))Instance variable set from the spacing prop.
--mutedCSS colorvar(--df-neutral-50)Outline variant hover fill.
--backgroundCSS colorvar(--df-neutral-0)Selected item fill.
--borderCSS colorvar(--df-neutral-100)Outline variant border.
--foregroundCSS colorvar(--df-neutral-900)Selected item label.
--df-corner-shapeCSS corner-shapevar(--df-corner-shape-round)Theme corner curve for all kit chrome. round = circular arcs; smooth = continuous squircle. Set with df-ui init --corner-shape, or override on :root. Default round.