Radio group
One of many. Unlike a checkbox, it cannot be unticked once ticked.
{/* 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. */}
One of many. Unlike a checkbox, it cannot be unticked once ticked.
Import
import { RadioGroup, Radio } from "@ir/ui";Watch out
- Figma's 1.5px border cannot render in a browser. Chrome floors a fractional border width to 1px, in plain CSS, at every pixel ratio (measured:
border:1.5pxandborder:1pxgive identical layout and identical computed values at DPR 1 and 2). 1px is not a change from the 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
Either preselect a sensible default, or add an explicit "None" option.
Don't — Offer a radio group with no default and no way to choose nothing.
A radio cannot be unticked by the person who ticked it. Without a default or a None, someone who clicks by accident is stuck with a value they never wanted and no way back.
Use Checkbox for any-of-many.
Don't — Use a radio group for options that are not mutually exclusive.
The control is a promise about the shape of the choice. A radio says picking this un-picks that, and if that is not true the form will fight people.
Use a Switch, or a single Checkbox.
Don't — Use two radios for on and off.
"On / Off" as two radios takes twice the space to say the same thing, and makes the reader compare two labels to find the one difference.
Use Select past about seven options.
Don't — List fifteen radios.
Radios are for a set you can take in at a glance and compare. Past that they are a list that happens to be circular, and a Select costs one click to show the same thing.
Order them by what they mean — severity, frequency, or least to most.
Don't — Order the options by how they arrived in the API.
People read a radio group as a scale whether or not you intended one. An arbitrary order invites them to infer a ranking that is not there.
Accessibility
- Radix renders a real radiogroup: arrow keys move between options and wrap, and the group is a single tab stop.
- The group needs a name — wrap it in a Field with a FieldLabel, or give the RadioGroup an aria-label.
- aria-invalid goes on the item, and colours the border and focus ring together.
Where it is drawn
Figma — structure from figma, measurements from figma.