Toggle

A two-state button that can be on or off, built on top of Base UI.

Installation

$ npx shadcn@latest add "/r/toggle.json"

Usage

Sizes

Available in three sizes to accommodate different layouts.

Props

PropTypeDefaultDescription
size"sm" | "md" | "lg""md"The size of the toggle.
pressedboolean-The controlled pressed state of the toggle.
defaultPressedbooleanfalseThe default pressed state of the toggle.
onPressedChange(pressed: boolean) => void-Event handler called when the pressed state changes.
disabledbooleanfalseWhether the toggle is disabled.
classNamestring-Additional CSS classes to apply to the toggle.