Switch

A sliding toggle for boolean on/off states.

Basic

Switch manages its own state when used uncontrolled via defaultChecked. Click to toggle.

Off
'use client';

import { useState } from 'react';
import { Switch } from '@venator-ui/ui';

export function SwitchExample() {
const [checked, setChecked] = useState(false);

return (
  <div className="flex items-center gap-3">
    <Switch checked={checked} onCheckedChange={setChecked} />
    <span className="text-sm text-neutral-500">{checked ? 'On' : 'Off'}</span>
  </div>
);
}

With label

Pass label to render a text label to the right of the track. Clicking the label also toggles the switch.

<Switch label="Enable notifications" />
<Switch label="Dark mode" defaultChecked />

Controlled

Pass checked and onCheckedChange to control the switch externally.

'use client';

import { useState } from 'react';
import { Switch } from '@venator-ui/ui';

export function ControlledSwitch() {
const [checked, setChecked] = useState(false);

return (
  <Switch
    checked={checked}
    onCheckedChange={setChecked}
    label="Airplane mode"
  />
);
}

Disabled

Set disabled to prevent interaction. Works in both checked and unchecked states.

<Switch label="Disabled off" disabled />
<Switch label="Disabled on" defaultChecked disabled />

Props

PropTypeDefaultDescription
checkedbooleanControlled checked state
defaultCheckedbooleanfalseInitial checked state in uncontrolled mode
onCheckedChange(checked: boolean) => voidCalled when the checked state changes
labelstringText label rendered to the right of the track
disabledbooleanfalsePrevents interaction and applies muted styles