Skip to content
Ballpoint

Toggle Group

A row of toggles where one stays pressed, or several, set edge to edge or spaced apart.

From shadcn/ui
Built on Base UI Toggle Group

Installation

pnpm dlx shadcn@latest add @ballpoint/toggle-group

Usage

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

<ToggleGroup multiple variant="outline" defaultValue={["bold"]}>
  <ToggleGroupItem value="bold" aria-label="Bold">B</ToggleGroupItem>
  <ToggleGroupItem value="italic" aria-label="Italic">I</ToggleGroupItem>
</ToggleGroup>

Examples

Single choice

Without `multiple`, pressing one releases the rest.

Aligned left.

Spacing and orientation

Spread the toggles out, or stack them in a column.

API reference

multiple
default false
boolean

Let more than one toggle stay pressed.

value / defaultValue
string[]

The values of the pressed toggles. Base UI keeps these as an array even for a single choice.

onValueChange
(value: string[]) => void

Called as the pressed set changes.

variant / size
as Toggle

Passed down to every item.

spacing
default 0
number

Gap between items in quarter-rems. At 0 their outlines touch.

orientation
default "horizontal"
"horizontal" | "vertical"

Which way the group runs.

Every other prop goes to Base UI's Toggle Group.