Skip to Content
zjkm-ui
Components

Switch

An on/off switch with a sliding knob.

Props
<Switch label="Wi-Fi" />

Installation

npx shadcn@latest add https://ui.zjkm.tech/r/switch.json
import { Switch } from "@/components/switch"

Using JavaScript? Set tsx: false in components.json and the CLI converts it.

New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.

Usage

An on/off switch with a sliding knob. It's a button with role="switch", so screen readers announce it as on or off.

import { Switch } from "@/components/switch";

export function WifiSetting() {
  return <Switch label="Wi-Fi" defaultChecked onChange={(on) => console.log(on)} />;
}

Props

PropTypeDefaultDescription
labelstringThe label.
defaultCheckedbooleanfalseStarting state.
checkedbooleanControls the state.
onChange(checked: boolean) => voidCalled when it flips.
colorstring"#16a34a"Track colour when on.
disabledbooleanfalseDisables it.
classNamestringClasses for the wrapper.

With reduced motion, the knob moves without sliding.

On this page