Toggle Group

A set of two-state buttons that can be toggled independently or as a single choice.

Installation

npx shadcn@latest add @fulldev/toggle-group

Usage

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

<ToggleGroup defaultValue="center" aria-label="Text alignment">
  <ToggleGroupItem value="left">Left</ToggleGroupItem>
  <ToggleGroupItem value="center">Center</ToggleGroupItem>
  <ToggleGroupItem value="right">Right</ToggleGroupItem>
</ToggleGroup>

Examples

Multiple

Use multiple with an array or a space-separated string to select more than one item.

Variants and Sizes

Set variant and size on the group to style every item. Set spacing={0} to join outlined items.

Vertical

The arrow keys follow the group orientation. Home and End move to the first and last enabled items.

Disabled

Disable the whole group or a single item.

API Reference

ToggleGroup

PropTypeDefaultDescription
defaultValuestring | string[][]Initial selected value or values.
multiplebooleanfalseAllows multiple selected items.
orientation"horizontal" | "vertical""horizontal"Sets arrow-key navigation direction.
loopbooleantrueWraps keyboard focus at either end.
disabledbooleanfalseBlocks interaction for the whole group.
variant"default" | "outline"item defaultApplies a visual variant to every item.
size"sm" | "default" | "lg"item defaultApplies a size to every item.
spacingnumber2Gap between items in Tailwind spacing units.

ToggleGroupItem

PropTypeDefaultDescription
valuestringrequiredUnique value for the item.
disabledbooleanfalseDisables the item.
variant"default" | "outline""default"Item variant when the group does not set one.
size"sm" | "default" | "lg""default"Item size when the group does not set one.

The root emits toggle-group:change with { value: string[] }. Dispatch toggle-group:set with { value: string | string[] } to update it from client code.

See the GitHub source code for the component source. See the data-slot docs for controller methods and full keyboard behavior.