Skip to content
synccn

Switch

Toggle with a springy thumb in three sizes.

Auto-sync

Changes sync every minute

Playground

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

Props

size
import { Switch } from "@/components/ui/switch";<Switch label="Email digests" />

Installation

$ pnpm dlx shadcn@latest add @synccn/switch

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

Usage

import { Switch } from "@/components/ui/switch";<Switch label="Auto-sync" defaultChecked />

API reference

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

  • checked
    boolean

    Controlled state.

  • defaultChecked
    boolean

    Default false

    Initial state when uncontrolled.

  • onCheckedChange
    (checked: boolean) => void

    Called with the new state.

  • label
    React.ReactNode

    Clickable label.

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

    Default "default"

    Track size.

  • disabled
    boolean

    Prevents changes.

  • id
    string

    Id for the control; generated if omitted.

  • className
    string

    Extra classes for the root element.

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

  • role switch with aria-checked. Give it a visible label or aria-label.

From the source

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

  • ARIA roles: switch
  • ARIA attributes: aria-checked
  • Shows a visible focus ring for keyboard users
  • Labels are tied to their controls