Switch
An immediate change. Flipping it does the thing — nothing is waiting on a Save button.
{/* Generated by scripts/build-component-docs.mjs — do not edit. The source is the component folder: guidance.json, the doc block and the props. Change those. */}
An immediate change. Flipping it does the thing — nothing is waiting on a Save button.
Import
import { Switch } from "@ir/ui";Watch out
- Figma draws the track border at 1.5px, which no browser can render — Chrome floors a fractional border width to 1px, in plain CSS, at every pixel ratio (measured:
border:1.5pxandborder:1pxproduce identical layout and identical computed values at DPR 1 and 2). So 1px is not a change from the Figma spec, it is the only form the spec can take on the web.
Variants
| Axis | Options | Default |
|---|---|---|
size | sm · md | md |
Do and don't
Use Switch for an immediate change, Checkbox for a form value.
Don't — Use a Switch for a value that a Save button confirms.
A switch says the change has already happened. Putting one in a form makes people flip it, press Save, and wonder which of the two actually did the work.
Apply each change as it is made, and say so if it takes a moment.
Don't — Pair a panel of switches with Save and Cancel.
Cancel cannot undo something that already took effect. If the change genuinely needs confirming, the control was never a switch.
Use a radio group — one tab stop, arrows to move, one answer.
Don't — Use two switches for two mutually exclusive options.
Two switches can both be on. If that state is impossible, the control is lying about the shape of the question.
Label the thing being switched — "Notifications" — and let on mean on.
Don't — Label a switch "Notifications off" and flip the meaning with its state.
A switch already carries the state. A negative label makes the on position mean off, which nobody reads correctly at a glance.
Hold the new position, show that it is saving, and explain it if it fails.
Don't — Flip the switch optimistically and let it snap back when the request fails.
A control that moves by itself reads as a bug, and people stop trusting what the position tells them.
Mute it, so it reads as a setting nobody can currently change.
Don't — Leave a disabled ON switch at full colour.
A live-looking switch invites a flip that does nothing, and no feedback follows to explain why.
Accessibility
- Radix supplies role="switch" and aria-checked. A switch is on or off now, not a value to be submitted — use Checkbox when it is the latter.
- Invalid is a ring, not a border: aria-invalid:shadow-ring-focus-danger. A mark has no border to recolour, which is the rule for every control of this shape.
- The track border goes transparent when the switch is on, and the focus ring is a separate layer that is unaffected. Border is decoration, ring is the indicator — keep them independent.
Where it is drawn
Figma — structure from figma, measurements from figma.