Switch
Status: stableAccessibility reviewedtenet-ui@0.4.0
import { Switch } from 'tenet-ui';Also accepts every prop of Omit<InputHTMLAttributes<HTMLInputElement>, 'size'>.
Source: src/components/Switch/Switch.tsx
Usage guidelines
Section titled “Usage guidelines”When to use: an immediate on/off setting that takes effect right away (e.g. “Enable notifications”). For a choice the user confirms later with a Save/Submit button, prefer Checkbox.
- Give it a label via the
labelprop (or an associatedaria-label). A switch with no name is unusable on a screen reader. - It is a real
<input type="checkbox" role="switch">— control it withchecked+onChange, or leave it uncontrolled withdefaultChecked. - Use
captionfor a one-line explanation; don’t pile a paragraph next to a toggle. - Use
size="small"only in dense rows (e.g. a settings table). Default tomedium. - Never build a toggle out of a
<div>with anonClick— you lose the role, the checked state, and keyboard support.
Do / Don’t
Section titled “Do / Don’t”- ✅
<Switch label="Enable notifications" defaultChecked /> - ✅ controlled:
<Switch label="Dark mode" checked={dark} onChange={e => setDark(e.target.checked)} /> - ❌
<Switch>with no label and noaria-label. - ❌ Using a Switch for a form value you submit on save — that’s a
Checkbox.
Examples
Section titled “Examples”5 stories for Switch — open in Storybook
- Default
components-switch--default - On
components-switch--on - With Caption
components-switch--with-caption - Small
components-switch--small - Disabled
components-switch--disabled
The full matrix (all args, controls, accessibility panel) is in Storybook.
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | — | Visible label rendered next to the switch. |
caption | ReactNode | — | Optional helper text under the label. |
size | 'small' | 'medium'SwitchSize | medium | Control track / knob scale. |
invalid | boolean | false | Mark the field as invalid (sets aria-invalid and a danger border). |