Radio Button
RadioButton represents a single option inside a mutually exclusive set managed by RadioButton.Group.
import { RadioButton } from '@/components/ui/wideset/radio-button/RadioButton';
<RadioButton.Group defaultValue="annual">
<RadioButton value="monthly" label="Monthly billing" description="Pay as you go, cancel anytime" />
<RadioButton value="annual" label="Annual billing" description="Two months free every year" />
</RadioButton.Group>Installation
pnpm dlx wideset add radio-button
Copies the component and any Wideset components it uses into your project.
Examples
Variants
Primary is the default for every ordinary choice. Danger marks the one option with consequences, such as deleting the data instead of archiving it. The colour is only a hint: the label has to say what happens.
import { RadioButton } from '@/components/ui/wideset/radio-button/RadioButton';
export default function RadioButtonVariants() {
return (
<RadioButton.Group defaultValue="delete" aria-label="When the project ends">
<RadioButton variant="primary" value="archive" label="Archive the project" />
<RadioButton variant="danger" value="delete" label="Delete the project and its files" />
</RadioButton.Group>
);
}Sizes
Large is the default and suits forms and settings. Small is for dense places such as filter panels and table toolbars. Keep one size within a group.
import { RadioButton } from '@/components/ui/wideset/radio-button/RadioButton';
export default function RadioButtonSizes() {
return (
<div className="gap-ws-16 flex flex-col">
{(['lg', 'sm'] as const).map((size) => (
<RadioButton.Group key={size} defaultValue="annual" aria-label="Billing period">
<RadioButton size={size} value="annual" label="Annual billing" />
<RadioButton size={size} value="monthly" label="Monthly billing" />
</RadioButton.Group>
))}
</div>
);
}States
A radio never stands alone: it lives in a group that owns the selection, and once one option is picked the user cannot clear it, only pick another. A disabled radio is skipped by the arrow keys and keeps its selection, so the user still sees what was chosen.
import { RadioButton } from '@/components/ui/wideset/radio-button/RadioButton';
const states = [
{ label: 'Unselected', selected: false, disabled: false },
{ label: 'Selected', selected: true, disabled: false },
{ label: 'Disabled', selected: false, disabled: true },
{ label: 'Disabled, selected', selected: true, disabled: true },
];
export default function RadioButtonStates() {
return (
<div className="gap-x-ws-11 gap-y-ws-7 grid grid-cols-[8rem_auto] items-center">
{states.map((state) => (
<div key={state.label} className="contents">
<span className="typography-caption-md text-ws-static-subtle">{state.label}</span>
<RadioButton.Group
aria-label={state.label}
defaultValue={state.selected ? 'annual' : undefined}
>
<RadioButton value="annual" label="Annual billing" disabled={state.disabled} />
</RadioButton.Group>
</div>
))}
</div>
);
}API reference
| Name | Description | Default |
|---|---|---|
value* | Unique value of the radio within the owning `RadioButton.Group`. string | — |
children | Composed label content such as `RadioButton.Label` and `RadioButton.Description`. ReactNode | — |
className | Additional CSS classes merged with the radio root element. string | — |
defaultMotion | Turns the component's built-in animations on or off. When omitted, inherits the value from the nearest `MotionProvider`. boolean | true |
description | Supplementary text shown below the shorthand label. Requires `label`. string | — |
disabled | Disables the radio visually and functionally. boolean | — |
id | Stable id of the radio input. When omitted, one is generated automatically. string | — |
label | Shorthand label rendered next to the radio. Mutually exclusive with `children`. string | — |
required | Marks the radio as required in a form context. boolean | — |
size | 'sm''lg' | 'lg' |
variant | 'primary''danger' | 'primary' |
Accessibility
- The shorthand
descriptionsits inside the label and is read with it. The composedRadioButton.Descriptionsits outside; clicking it still selects the radio, but give it anidand point the radio’saria-describedbyat it so it is announced. - Name the group, not each radio: see RadioButtonGroup.
import { RadioButton } from '@/components/ui/wideset/radio-button/RadioButton';
<RadioButton.Group defaultValue="annual">
<RadioButton value="monthly" label="Monthly billing" description="Pay as you go, cancel anytime" />
<RadioButton value="annual" label="Annual billing" description="Two months free every year" />
</RadioButton.Group>