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
labelstring—Text label rendered alongside the switch
checkedboolean—Controlled checked state
defaultCheckedbooleanfalseInitial checked state for uncontrolled usage
onCheckedChange(checked: boolean) => void—Callback fired when the checked state changes
disabledbooleanfalsePrevent interaction with the switch
idstring—Used for label association (auto-generated if not provided)
classNamestring—Additional Tailwind classes applied to the switch root