View fulldotdev/ui on GitHub

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="a">
  <ToggleGroupItem value="a">A</ToggleGroupItem>
  <ToggleGroupItem value="b">B</ToggleGroupItem>
  <ToggleGroupItem value="c">C</ToggleGroupItem>
</ToggleGroup>

Composition

ToggleGroup
├── ToggleGroupItem
└── ToggleGroupItem

Outline

Use variant="outline" for an outline style.

Size

Use the size prop to change the size of the toggle group.

Spacing

Use spacing to set the gap between items. The default is 2; use spacing={0} for connected items.

Vertical

Use orientation="vertical" for vertical toggle groups. Arrow keys follow the orientation.

Disabled

Custom

A custom toggle group that shows the selected value through the toggle-group:change event.

RTL

Set dir="rtl" on the group or a parent element.

API Reference

Source: src/components/ui/toggle-group

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 data-slot docs for controller methods and full keyboard behavior.