Switch

A toggle for an instant, self-applying boolean, built on Radix Switch. Use it for settings that take effect immediately (notifications, airplane mode); reach for a Checkbox when the choice is submitted with a form.

Installation#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Add this component (its dependencies come along)npx koalaui-cli@latest add switch

Usage#

usage.tsxTSX
import { Switch } from "@/components/ui/switch"export function Example() {  return (    <label htmlFor="airplane" className="flex items-center gap-2.5">      <Switch id="airplane" defaultChecked />      Airplane mode    </label>  )}

States#

Off rests on the input fill; on slides the thumb across a brand (accent) track. The thumb carries a shadow so it reads on both states in every theme.

Off
On
Disabled
Disabled on

Controlled#

Drive the switch from state with checked and onCheckedChange, or leave it uncontrolled with defaultChecked.

Enabled

In a settings list#

The common shell: a label and description on the left, the switch trailing right. The whole row is the label, so the full width is the hit target.

FAQ#

Use a Switch for an instant, self-applying boolean that takes effect immediately, like notifications or airplane mode. Reach for a Checkbox when the choice is only submitted later with a form.