Skip to content
Drivn

Toggle

Toggle button with pressed state, single and multiple selection groups, and accessible aria-pressed support.

Preview

Installation

npx drivn add toggle

Usage

1import { Toggle } from "@/components/ui/toggle"
2import { Bold } from "lucide-react"
3
4export default function Page() {
5 return (
6 <Toggle>
7 <Bold className="h-4 w-4" />
8 Bold
9 </Toggle>
10 )
11}

Outline Variant

Border style for a more defined appearance.

Sizes

Three sizes: sm, md, and lg.

Single Selection

Radio-like toolbar — only one toggle active at a time, press again to deselect.

Multiple Selection

Checkbox-like toolbar — toggle items independently.

Disabled

Disable individual toggles or the entire group.

Vertical

Stack toggles vertically with orientation.

API Reference

Toggle

PropTypeDefaultDescription
pressedboolean—Controlled pressed state
defaultPressedbooleanfalseInitial pressed state (uncontrolled)
onChange(pressed: boolean) => void—Callback fired when pressed state changes
valuestring—Item value when used inside Toggle.Group
variant"default" | "outline""default"Visual style variant
size"sm" | "md" | "lg""md"Toggle size
disabledbooleanfalseDisables the toggle
classNamestring—Additional CSS classes
...propsButtonHTMLAttributes<HTMLButtonElement>—All standard HTML button attributes are supported

Toggle.Group

PropTypeDefaultDescription
type"single" | "multiple"—Selection mode — single allows one active toggle, multiple allows many
defaultValuestring | string[]—Initial value (uncontrolled)
valuestring | string[]—Current value (controlled)
onValueChange(value: string | string[]) => void—Callback fired when the value changes
orientation"horizontal" | "vertical""horizontal"Layout direction of the group
disabledbooleanfalseDisables all toggles in the group
classNamestring—Additional CSS classes for the group wrapper