Switch
A single boolean toggle on Ark UI's Switch machine — sliding track + thumb, inline label, built-in description / error, native form submission, and full keyboard / ARIA.
Switch is a single boolean control styled as a sliding track + thumb, with an inline label. Use it for settings that take effect immediately; reach for Checkbox when the value is part of a form to submit. description / error / required are built in via Field. It implements the kit's form-control contract — name submits, and ref / onBlur land on the hidden input — so it binds to react-hook-form, TanStack Form, or a plain <form> with no glue.
import { Switch } from '@42/ui-react/switch';
<Switch label="Available for evals" />Playground
Component
Dir
Presets
Props
Code
<Component label="Available for evals" size="md" />Sizes
Five sizes — xs through xl — matching the rest of the family. The track and thumb scale together.
Code
<Switch size="xs" label="xs" defaultChecked /><Switch size="sm" label="sm" defaultChecked /><Switch size="md" label="md" defaultChecked /><Switch size="lg" label="lg" defaultChecked /><Switch size="xl" label="xl" defaultChecked />Colors
The resting track is palette-independent; only the checked fill and the focus ring adopt color. Set data-color once on the root and every kit palette tints for free.
Code
<Switch color="brand" label="brand" defaultChecked /><Switch color="green" label="green" defaultChecked /><Switch color="blue" label="blue" defaultChecked /><Switch color="purple" label="purple" defaultChecked /><Switch color="red" label="red" defaultChecked />Disabled
disabled dims the control and blocks interaction.
Code
<Switch label="Disabled" disabled /><Switch label="Disabled, on" disabled defaultChecked />With description & error
description (helper text) and error sit below the control via the built-in Field. Passing error flips the track to the invalid (red) state; required adds the semantic flag and a red asterisk on the label.
Code
<Switchlabel="Evaluation reminders"description="We'll only ping you about peer evaluations."defaultChecked/><Switch label="Accept the terms" required /><Switch label="Accept the terms" error="You must accept to continue" />Controlled
Drive the checked state from state. onCheckedChange hands you the next boolean.
'use client';
import { useState } from 'react';
import { Switch } from '@42/ui-react/switch';
export function AvailabilityToggle() {
const [on, setOn] = useState(false);
return <Switch label="Available for evals" checked={on} onCheckedChange={setOn} />;
}Forms
Switch renders a hidden native <input type="checkbox">, so a name wires it into native <form> submission and FormData. The submitted value defaults to "on".
<form action={save}>
<Switch name="notifications" value="enabled" label="Enable notifications" />
</form>API
Prop
Type
Accessibility
- Full Switch model from Ark:
Space/Entertoggles, focus shows the ring, and the track / label / description / error associations are wired (the latter via the built-inField). - A hidden native
<input type="checkbox">backs form submission and carriesaria-checked; the visual track is presented as the switch. invalid(orerror) setsaria-invalidon the input.- RTL is honored via the document
dir— the track and label mirror automatically.
RadioGroup
A single-choice set of options on Ark UI's RadioGroup machine — inline labels, built-in label / description / error, native form submission, and full keyboard / ARIA.
Segment Group
A segmented single-choice control on Ark UI's SegmentGroup machine — a compact, always-visible row of mutually exclusive segments with a sliding pill, built-in label / description / error, and native form submission.