Components
Switch
Base UI on/off controls with accessible switch semantics and token styling.
Switch is a Base UI switch with token styling. It supports controlled and uncontrolled state,
labels, sizes, form submission, and Space-key toggling.
Import it from @orkest/ui/client.
Live preview#
import { useState } from 'react';
import { Switch } from '@orkest/ui/client';
export function Example() {
const [enabled, setEnabled] = useState(true);
return (
<Switch
label="Email notifications"
checked={enabled}
onCheckedChange={setEnabled}
/>
);
}States and sizes#
import { Stack } from '@orkest/ui';
import { Switch } from '@orkest/ui/client';
export function Example() {
return (
<Stack gap={3}>
<Switch label="Off" />
<Switch label="On" defaultChecked />
<Switch label="Disabled" disabled />
<Switch label="Small" size="sm" defaultChecked />
<Switch label="Large" size="lg" defaultChecked />
</Stack>
);
}Props#
| Prop | Type | Default |
|---|---|---|
checked | boolean | — |
| Controlled on/off state. | ||
defaultChecked | boolean | false |
| Initial state for uncontrolled usage. | ||
onCheckedChange | (checked: boolean, eventDetails) => void | — |
| Called when the switch changes. | ||
disabled | boolean | false |
| Disables the switch. | ||
readOnly | boolean | false |
| Allows focus but prevents changing the value. | ||
required | boolean | false |
| Requires the switch for form validation. | ||
name | string | — |
| Form field name. | ||
value | string | — |
| Value submitted with the form. | ||
inputRef | Ref<HTMLInputElement> | — |
| Ref to the hidden native input used for form submission. | ||
size | 'sm' | 'md' | 'lg' | 'md' |
| Track, thumb, and label size. | ||
label | ReactNode | — |
| Label rendered beside the switch. | ||
native attributes | Base UI Switch Root props | — |
| ARIA attributes, id, form, style, and ref are forwarded to the switch root. className styles the label wrapper. | ||
Accessibility#
- Renders a Base UI switch with
role="switch"and a hidden native input for form submission. - Space toggles the switch while focused; Base UI handles the keyboard interaction.
- The optional
labelis an implicit label. When omitting it, providearia-label,aria-labelledby, or useFieldLabel. - Focus is shown on the track with
:focus-visible. - The thumb transition is disabled when
prefers-reduced-motion: reduceis active.