Skip to documentation

Design system / Molecules

Molecule / Selection

ToggleGroup

ToggleGroup combines Toggle-styled items under a single- or multiple-selection contract. Bounded Context supplies variants and spacing. The caller supplies selection meaning and persistence.

Live example

Live preview

Current component with fictional data. Example changes are not persisted.

Responsibility

Related Toggle-styled items share a group selection contract. Local Context distributes style configuration and spacing. Single selection can still be empty; use a radio contract when required-choice semantics are needed.

Public contract

The table describes supported inputs, exported parts and caller responsibilities. A callback supplies a command, such as saving a draft. These notes are maintained manually; check current source types before integration.

Maintained component API notes; current source is authoritative
Prop / partTypeRequirementResponsibility
typesingle | multipleRadix Root · requiredDetermines string versus string-array value.
value / defaultValue / onValueChangeRadix Root propsControlled or uncontrolledConsumer binds group values.
variant / sizetoggleVariants propsRoot and ItemNonempty Context values take precedence over item props.
spacingnumberRoot · default 0Sets --gap and joined-item geometry when zero.
value / disabledRadix Item propsValue requiredItem identity and availability.

API notes are curated documentation, not generated types. The source linked above is the current implementation; update these notes alongside API changes.

State and behavior

Identify which values the caller controls and which behavior the component or underlying primitive owns. A local example does not supply persistence, authorization or a complete product lifecycle.

Radix manages selection when uncontrolled. Context passes styling and spacing, not a global product state. The consumer owns meaning and persistence.

Dependencies

  • Radix ToggleGroup Root and Item
  • toggleVariants()
  • React Context
  • cn()

Token and styling contract

These notes identify theme roles, utilities and direct style values used by the source. Direct colors or timings are implementation exceptions, not recommendations to bypass the theme.

toggleVariants()
Appearance inherited from Toggle.
--gap / --spacing()
Source group spacing calculation.
data-[spacing=0] rounded/border rules
Joined-item treatment.

Boundaries and limitations

  • Single mode can represent no selection; do not assume a radio group’s policy.
  • Changing Context styling precedence can affect all items; numeric spacing is not a pixel prop.

Where to make a change

Change grouping/context in toggle-group.tsx and individual control appearance in toggle.tsx; keep settings and operation policy in the consumer.

Selected real uses

No product consumer is recorded in this entry's selected-use notes. The implementation and specimen establish availability, not adoption. These notes are not an exhaustive usage scan.

These traces describe selected uses, not every dependency. Repository-only paths are shown as references; only approved files have public source views.

Usage contract

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

<ToggleGroup type="multiple" value={formats} onValueChange={setFormats} aria-label="Formats">
  <ToggleGroupItem value="bold" aria-label="Bold">B</ToggleGroupItem>
  <ToggleGroupItem value="italic" aria-label="Italic">I</ToggleGroupItem>
</ToggleGroup>

Illustrative consumer bindings, not a self-contained product workflow. Live examples supply only local state or explicit fictional props.

All molecules
Current components and theme tokens. Fictional example data. Source views refresh on deployment; authors maintain contract notes.