View fulldotdev/ui on GitHub

Toggle

A two-state button that can be either on or off.

Installation

npx shadcn@latest add @fulldev/toggle

Usage

import { Toggle } from "@/components/ui/toggle"
<Toggle>Toggle</Toggle>

Toggle renders a button with aria-pressed. Use defaultPressed for the initial state. Style the pressed state with aria-pressed: or, on children, group-aria-pressed/toggle:.

Outline

Use variant="outline" for an outline style.

With Text

Size

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

Disabled

RTL

Set dir="rtl" on the toggle or a parent element.

API Reference

Source: src/components/ui/toggle

PropTypeDefault
variant"default" | "outline""default"
size"default" | "sm" | "lg""default"
defaultPressedbooleanfalse
disabledbooleanfalse

toggleVariants gives the same classes to a custom element. See the data-slot docs for events such as toggle:change.