components / form
Radio Group
Pick exactly one option from a small set, with arrow-key navigation.
522 B gzip client componentbase ui · radio, radio-group
radio-group-default.tsx
import { Radio, RadioGroup } from "@/components/ui/radio-group";
const plans = [
{ value: "free", label: "Free" },
{ value: "pro", label: "Pro" },
{ value: "team", label: "Team" },
];
export default function RadioGroupDefault() {
return (
<RadioGroup aria-label="Plan" className="text-sm" defaultValue="pro">
{plans.map((p) => (
<label className="flex items-center gap-2" htmlFor={p.value} key={p.value}>
<Radio id={p.value} value={p.value} /> {p.label}
</label>
))}
<label className="flex items-center gap-2 text-muted-foreground" htmlFor="enterprise">
<Radio disabled id="enterprise" value="enterprise" /> Enterprise (contact us)
</label>
</RadioGroup>
);
}Installation
$ npx shadcn@latest add https://cd-ui.vercel.app/r/radio-group.jsonfirst time? set up components.json and the theme first: see installation.
Usage
import { Radio, RadioGroup } from "@/components/ui/radio-group"
<RadioGroup aria-label="Plan" defaultValue="pro">
<label className="flex items-center gap-2">
<Radio value="free" /> Free
</label>
<label className="flex items-center gap-2">
<Radio value="pro" /> Pro
</label>
</RadioGroup>API
RadioGroup
Base UI · RadioGroupGroup of exclusive options. Give it a name with aria-label or a visible label.
| prop | type | default |
|---|---|---|
value · defaultValueControlled or initial value. | string | - |
onValueChangeCalled when another option is chosen. | (value) => void | - |
nameTo submit in a form. | string | - |
disabled · requiredDisabled and required states. | boolean | - |
classNameExtra classes, merged with | string | - |
Radio
Base UI · Radio.RootOne option. The dot inside grows in 160ms when selected.
| prop | type | default |
|---|---|---|
valueOption value. | string | - |
classNameExtra classes, merged with | string | - |
Keyboard
| key | action |
|---|---|
| ↑↓←→ | Moves the selection between options. |
| Tab | Enters and leaves the group. |
| Space | Selects the focused option. |
Accessibility
- Wrap each
Radioin a<label>so its text is the accessible name and clicking the text selects it.