Skip to content

shadcn.io is not affiliated with official shadcn/ui

Shadcn Toggle Group for React

Toggle buttons for selecting a value.

Installation

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

Anatomy

useToggleGroup
└── ToggleGroupItem

Usage

import { BoldIcon, ItalicIcon, UnderlineIcon } from "lucide-react";
import {
  ToggleGroup,
  ToggleGroupItem,
} from "@/components/ui/toggle-group";
<ToggleGroup multiple variant="outline">
  <ToggleGroupItem aria-label="Toggle bold" value="bold">
    <BoldIcon aria-hidden="true" />
  </ToggleGroupItem>
  <ToggleGroupItem aria-label="Toggle italic" value="italic">
    <ItalicIcon aria-hidden="true" />
  </ToggleGroupItem>
  <ToggleGroupItem aria-label="Toggle strikethrough" value="strikethrough">
    <UnderlineIcon aria-hidden="true" />
  </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

Outline

Use variant="outline" for an outline style.

Sizes

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

Spacing

Use spacing to add spacing between toggle group items.

Vertical

Use orientation="vertical" for vertical toggle groups.

Disabled

A disabled toggle group.

Font Weight Selector

A custom toggle group example.

Rtl

Right-to-left toggle group. See the RTL configuration guide for document direction.

API Reference

ToggleGroup

div

PropType
type"multiple"
valuestring[]): void
dir?RovingFocusGroupProps["dir"]
loop?RovingFocusGroupProps["loop"]
AttributeType
CSS variableType
--gapstring

ToggleGroupItem

button

PropType
AttributeType
data-spacing?string