Skip to content
synccn

Toggle

A button that stays pressed or unpressed.

Playground

Change the props and copy the code. The controls come from the component's TypeScript types.

Props

variant
size
import { Toggle } from "@/components/ui/toggle";<Toggle aria-label="Bold">Bold</Toggle>

Installation

$ pnpm dlx shadcn@latest add @synccn/toggle

First time in this project? Connect synccn with one command.

Usage

import { Toggle } from "@/components/ui/toggle";<Toggle aria-label="Bold"><Bold /></Toggle>

API reference

Generated from the component's TypeScript types, so it always matches the code.

Toggle

A two-state button: pressed or not.

  • pressed
    boolean

    Controlled state.

  • defaultPressed
    boolean

    Default false

    Initial state when uncontrolled.

  • onPressedChange
    (pressed: boolean) => void

    Called with the new state.

  • variant
    "default" | "outline"

    Default "default"

    Border style.

  • size
    "sm" | "default" | "lg"

    Default "default"

    Size.

  • className
    string

    Extra classes for the root element.

  • children
    React.ReactNode

    Content to render.

Also accepts every standard <button> attribute, and forwards its ref.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseControllable (works controlled or uncontrolled)

npm packages

Keyboard

  • SpaceorEnterToggle

Accessibility

  • Reports its state with aria-pressed.

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA attributes: aria-pressed
  • Shows a visible focus ring for keyboard users