MenuChevron Down
ToggleGroup - Docs - Artefact

ToggleGroup

Forms
Smart auto-detect

Introduction

A set of toggle buttons for single- or multiple-selection, exclusive or inclusive — e.g. text-formatting controls (bold/italic/underline) or a view-switcher.

Hydration

Tier 2 — smart auto-detect. A ToggleGroup renders as static HTML and ships no client JS unless a behavioral signal is present. Pass interactive={true} to force hydration, or interactive={false} to force a static render.

It hydrates as an island when any of the following signals is present (or interactive={true} is set):

  • value (controlled selection)
  • defaultValue (uncontrolled initial selection)
  • onValueChange
interactive propResult
omitted, no signalStatic — no client JS
omitted, a signal presentHydrates as an island
trueHydrates as an island
falseStatic — no client JS

Usage

import { ToggleGroup } from "../components/ui";

export default function MyPage() {
  return (
    <ToggleGroup
      multiple
      defaultValue={["bold"]}
      items={[
        { label: "B", value: "bold" },
        { label: "I", value: "italic" },
        { label: "U", value: "underline" },
      ]}
    />
  );
}

Custom Composition

Pass children instead of items for full control over each button's content:

import { ToggleGroup } from "../components/ui";

export default function MyPage() {
  return (
    <ToggleGroup defaultValue={["list"]}>
      <ToggleGroup.Item value="grid">Grid</ToggleGroup.Item>
      <ToggleGroup.Item value="list">List</ToggleGroup.Item>
    </ToggleGroup>
  );
}

Props

Root

PropTypeDescription
valuestring[]The currently pressed values (controlled).
defaultValuestring[]The initially pressed values (uncontrolled).
onValueChange(value: string[]) => voidCalled when the selection changes.
multiplebooleanAllow more than one item pressed at once. Default false (single, toggleable-off selection).
disabledbooleanDisables every item.
orientation"horizontal" | "vertical"Layout flow, and the axis Arrow keys roam. Default "horizontal".
idstringThe root element's id.
variant"outline" | "ghost"Visual style. Default "outline".
size"sm" | "md" | "lg"Visual size. Default "md".
interactivebooleanOverrides the hydration decision (see above).
classstringCustom CSS classes for the root element.

Default composition

PropTypeDescription
itemsToggleGroupItem[]Buttons to render when children is omitted.

ToggleGroupItem

PropTypeDescription
valuestringThe item's unique value.
labelstring | JSX.ElementThe button's display content.
disabledbooleanDisables this button.

Sub-components

PartDescription
ToggleGroup.ItemOne toggle button. Requires a value prop; renders role="checkbox" in multiple mode or role="radio" otherwise.

Accessibility

  • The root has role="group".
  • Items render role="checkbox" + aria-pressed when multiple, or role="radio" + aria-checked otherwise.
  • Arrow keys (Right/Down to move forward, Left/Up to move back) roam focus between enabled items; Home/End jump to the first/last enabled item — matching orientation.
  • data-state (on/off) and data-disabled are mirrored onto each item for styling.