Skip to content
shadcn.io

shadcn.io is not affiliated with official shadcn/ui

Shadcn Toggle Group for React and Tailwind

Toggle buttons for selecting a value.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/toggle-group.json

Anatomy

useToggleGroup
└── ToggleGroupItem

Usage

import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";
<ToggleGroup defaultValue={["bold"]} multiple>
  <ToggleGroupItem aria-label="Toggle bold" value="bold">
    <BoldIcon />
  </ToggleGroupItem>
  <ToggleGroupItem aria-label="Toggle italic" value="italic">
    <ItalicIcon />
  </ToggleGroupItem>
  <ToggleGroupItem aria-label="Toggle underline" value="underline">
    <UnderlineIcon />
  </ToggleGroupItem>
</ToggleGroup>

Accessibility

KeyDescription
Enter
Activate the focused control.
Space
Activate the focused control.
Tab
Toggle.
ArrowLeft
Move to the previous item.
ArrowRight
Move to the next item.
ArrowUp
Move to the previous item.
ArrowDown
Move to the next item.
Home
Move to the first item.
End
Move to the last item.

Demos

Controlled

Custom

Disabled

Disabled Item

Ghost

Horizontal

Outline

Single

Size Lg

Size Sm

Spacing

Vertical

API Reference

ToggleGroup

button

PropType
AttributeType

useToggleGroup

div

PropType
CSS variableType

ToggleGroupItem

button

PropType
AttributeType

useToggleGroup

PropType