RadioGroup
A single-choice group of RadioItems (role="radiogroup").
- One tab stop (the selected item, else the first enabled one); arrow keys move focus and select (APG radio group), Home/End jump to the ends, disabled items are skipped. A key pressed on a link inside an item's label stays the link's: it neither moves focus nor selects. Items may sit inside Fragments or wrapper elements. Every item needs its own value (a development warning names a value that several items share).
- Inside a Field it is named by the Field label (aria-labelledby) and described by its hint and error.
- With name (or required) it takes part in native forms; a form reset restores defaultValue.
Use RadioGroup.Item (or the flat RadioGroupItem/RadioItem names) for the items. React Server Components cannot access the dotted form, so they import the flat names; dotted access needs a client file. An element of your own (a card with a title and a description) becomes one of the group's radios through useRadioGroupItem, and useRadioGroupContext reads the group's value from content inside it.
Examples
Default
export const Default: Story = {
args: {
defaultValue: 'apple',
},
render: (args) => (
<RadioGroup {...args}>
<RadioItem value="apple" label="Apple" />
<RadioItem value="banana" label="Banana" />
<RadioItem value="cherry" label="Cherry" />
</RadioGroup>
),
};Horizontal
export const Horizontal: Story = {
args: {
'aria-label': 'Size',
orientation: 'horizontal',
defaultValue: 'medium',
},
render: (args) => (
<RadioGroup {...args}>
<RadioItem value="small" label="Small" />
<RadioItem value="medium" label="Medium" />
<RadioItem value="large" label="Large" />
</RadioGroup>
),
};Horizontal Stacked
export const HorizontalStacked: Story = {
args: {
'aria-label': 'Size',
orientation: 'horizontal',
labelPosition: 'below',
defaultValue: 'medium',
},
render: (args) => (
<RadioGroup {...args}>
<RadioItem value="small" label="Small" />
<RadioItem value="medium" label="Medium" />
<RadioItem value="large" label="Large" />
</RadioGroup>
),
};Dotted Items
export const DottedItems: Story = {
args: {
'aria-label': 'Delivery',
defaultValue: 'standard',
},
render: (args) => (
<RadioGroup {...args}>
<RadioGroup.Item value="standard" label="Standard" />
<RadioGroup.Item value="express" label="Express" />
</RadioGroup>
),
};Disabled
export const Disabled: Story = {
args: {
'aria-label': 'Disabled group',
defaultValue: 'a',
disabled: true,
},
render: (args) => (
<RadioGroup {...args}>
<RadioItem value="a" label="Option A" />
<RadioItem value="b" label="Option B" />
</RadioGroup>
),
};Disabled Item
export const DisabledItem: Story = {
args: {
'aria-label': 'Plan',
},
render: (args) => (
<RadioGroup {...args}>
<RadioItem value="free" label="Free" disabled />
<RadioItem value="pro" label="Pro" />
<RadioItem value="team" label="Team" />
</RadioGroup>
),
};Controlled
Selected: red
export const Controlled: Story = {
args: {
'aria-label': 'Color',
},
render: function ControlledRadioGroup(args) {
const [value, setValue] = useState('red');
return (
<div className="flex flex-col gap-2">
<RadioGroup
{...args}
value={value}
onValueChange={(next) => {
setValue(next);
args.onValueChange?.(next);
}}
>
<RadioItem value="red" label="Red" />
<RadioItem value="green" label="Green" />
<RadioItem value="blue" label="Blue" />
</RadioGroup>
<p className="text-wave-body-1 text-wave-foreground">Selected: {value}</p>
</div>
);
},
};In Form
export const InForm: Story = {
args: {
'aria-label': 'Shipping speed',
name: 'shipping',
required: true,
},
render: (args) => (
<form className="flex flex-col items-start gap-3" onSubmit={(e) => e.preventDefault()}>
<RadioGroup {...args}>
<RadioItem value="standard" label="Standard" />
<RadioItem value="express" label="Express" />
</RadioGroup>
<Button type="submit" appearance="primary">
Continue
</Button>
</form>
),
};Label With Subtext
export const LabelWithSubtext: Story = {
args: {
'aria-label': 'Delivery speed',
defaultValue: 'standard',
},
render: (args) => {
const option = (title: string, detail: string) => (
<span className="flex flex-col">
<span>{title}</span>{' '}
<span className="text-wave-caption-1 text-wave-muted-foreground">{detail}</span>
</span>
);
return (
<RadioGroup {...args}>
<RadioItem
value="standard"
label={option('Standard', 'Arrives in 3 to 5 business days.')}
/>
<RadioItem
value="express"
label={option('Express', 'Arrives tomorrow when ordered before 14:00.')}
/>
</RadioGroup>
);
},
};Custom Radio Card
export const CustomRadioCard: Story = {
args: {
'aria-label': 'Plan',
defaultValue: 'pro',
},
render: (args) => (
<RadioGroup {...args}>
<PlanCard value="free" title="Free" description="One project and community support." />
<PlanCard value="pro" title="Pro" description="Unlimited projects and email support." />
<PlanCard
value="team"
title="Team"
description="Shared workspaces. Ask your administrator to enable it."
disabled
/>
<PlanSummary />
</RadioGroup>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
value | string | No | Controlled selected value ( | |
defaultValue | string | No | '' | Initial selected value for uncontrolled usage (also the value a form reset restores). |
onValueChange | (value: string) => void | No | Called with the newly selected value when the selection changes (not when re-selecting). | |
orientation | 'horizontal' | 'vertical' | No | 'vertical' | Layout of the radio items (also |
labelPosition | 'after' | 'below' | No | 'after' | Where the items draw their label, unless an item sets its own |
disabled | boolean | No | Disables every item of the group. | |
name | string | No | Form field name. With a name, the selected value is submitted with the form. No name is generated: without one the group adds nothing to | |
required | boolean | No | A value must be selected before the form can be submitted (native validation). | |
form | string | No | Id of the form the group belongs to, when it is rendered outside that form. | |
ref | React.Ref<HTMLDivElement> | No | Ref to the |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
RadioGroup.Item
Stable class names
| Part | Class |
|---|---|
root | wave-radio-group |