Menu

Toggle

Pressable on/off button + group. 2 variants × 2 values × 2 sizes.

Installation

$ npx uix-ui@latest add toggle

This copies the file into components/ui/toggle.tsx in your project. npx shadcn@latest add @uix/toggle works too.

Usage

toggle.tsx
import { Toggle, ToggleGroup } from "@/components/ui/toggle";

<ToggleGroup attached aria-label="Text style">
  <Toggle variant="outline" defaultPressed>Hot</Toggle>
  <Toggle variant="outline">Iced</Toggle>
  <Toggle variant="outline">Cold brew</Toggle>
</ToggleGroup>

Examples

Toggle group

Props

Toggle props

PropTypeDefaultDescription
variantdefault | outline"default"
pressedfalse | true–
sizesm | md"md"
defaultPressedbooleanfalseStart pressed (uncontrolled). Pass the variant prop "pressed" to control it.
onPressedChange(pressed: boolean) => void–
iconReact.ReactNode–Icon before the label.

ToggleGroupProps

PropTypeDefaultDescription
attachedbooleanfalseJoins the toggles into one bar that shares a hairline (use the outline variant).

Everything else is passed to the root element, so className, aria-* and event handlers work as usual.

Dependencies

Installed for you by the CLI.

  • class-variance-authority
  • clsx
  • tailwind-merge
  • lib/utils.ts
This file exports 2 parts: Toggle, ToggleGroup. Use only the ones you need.
esc

↑↓ to navigate · ↵ to select · esc to close