Switch

A binary on/off switch with an optional label. Built on Radix UI Switch, with smooth thumb animation and full keyboard accessibility. Renamed from Toggle in v0.3.0 to match the underlying Radix primitive.

Usage

import { Switch } from "@bloomkit/react";
 
<Switch
  label="Enable notifications"
  onCheckedChange={(checked) => console.log(checked)}
/>

Controlled

const [enabled, setEnabled] = useState(false);
 
<Switch
  label="Dark mode"
  checked={enabled}
  onCheckedChange={setEnabled}
/>

Without label

<Switch
  aria-label="Toggle dark mode"
  onCheckedChange={(checked) => setDarkMode(checked)}
/>

Props

PropTypeDefaultDescription
labelstringText label rendered alongside the switch
checkedbooleanControlled checked state
defaultCheckedbooleanfalseInitial checked state for uncontrolled usage
onCheckedChange(checked: boolean) => voidCallback fired when the checked state changes
disabledbooleanfalsePrevent interaction with the switch
idstringUsed for label association (auto-generated if not provided)
classNamestringAdditional Tailwind classes applied to the switch root