RadioGroup
One choice from a set, as a group with its question.
Examples
Playground
Size
States
The group in each state. An option can be disabled on its own (Extra large).
rest
Size
focus
Size
error
SizeChoose a size to continue.
Arrows move the selection
Tab into the group, then use the arrow keys. The group is one tab stop and the arrows change the selection, which comes free from native inputs sharing a name. Disabled options are skipped.
Size
Orientation
Vertical by default; horizontal for two or three short options.
vertical
Size
horizontal
Size
Install
npx shadcn add @hipuku/radio-groupUsage
import { RadioGroup } from '@/components/haus/components/Radio'
<RadioGroup
label="Plan"
name="plan"
value={plan}
onChange={setPlan}
options={[
{ label: 'Free', value: 'free' },
{ label: 'Team', value: 'team', hint: 'Up to 20 people' },
]}
/>API
RadioGroup also takes its element's own attributes and forwards its ref. className lands on the
root.
| Prop | Type | Description |
|---|---|---|
onChange | ((value: string, event: React.ChangeEvent<HTMLInputElement>) => void) | (value, event), matching Checkbox and Toggle. The value first because a
group has no single control and the value is the whole point; the event
second so event.target.name is reachable. |
namerequired | string | |
value | string | |
defaultValue | string | |
optionsrequired | RadioOption[] | |
label | string | |
error | string | |
required | boolean | |
orientation | "horizontal" | "vertical" |
Options
Options come from options, not from children. Each has a label, a value, and an optional
hint and disabled. orientation="horizontal" lays them in a row. onChange gives you
(value, event), and it is uncontrolled unless you pass value.
Accessibility
- One tab stop for the whole group. The arrow keys move the selection.
- Announced as a group named by
label, so the question is read before the options. requiredanderrorsetaria-requiredandaria-invalidon the group, and an error is announced when it appears.