Radio Group
A set of radio buttons where only one can be selected at a time.
"use client"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
export default function RadioGroupDemo() {
return (
<RadioGroup defaultValue="auto">
<Label className="gap-[5px] font-medium">
<RadioGroupItem value="light" /> Light
</Label>
<Label className="gap-[5px] font-medium">
<RadioGroupItem value="dark" /> Dark
</Label>
<Label className="gap-[5px] font-medium">
<RadioGroupItem value="auto" /> Automatic
</Label>
</RadioGroup>
)
}Installation
pnpm dlx shadcn@latest add @cupertinoui/radio-groupThe first install also adds the macOS theme. See Installation to set up the registry.
Usage
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
<RadioGroup defaultValue="auto">
<Label>
<RadioGroupItem value="auto" /> Automatic
</Label>
</RadioGroup>Examples
Horizontal
"use client"
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
export default function RadioGroupHorizontal() {
return (
<div className="flex items-center gap-4">
<span className="text-mac-body">Sidebar icon size:</span>
<RadioGroup defaultValue="medium" className="flex gap-4">
{["Small", "Medium", "Large"].map((size) => (
<Label key={size} className="gap-[5px] font-medium">
<RadioGroupItem value={size.toLowerCase()} /> {size}
</Label>
))}
</RadioGroup>
</div>
)
}API Reference
Every part forwards the props of the underlying Base UI Radio Group part. The props below are the ones CupertinoUI adds or changes.
RadioGroup
| Prop | Type | Description |
|---|---|---|
value | string | The selected value (controlled). |
defaultValue | string | The initially selected value. |
onValueChange | (value: string) => void | Called when the selection changes. |
className | string | Extra classes, merged with the component's own. |
RadioGroupItem
| Prop | Type | Description |
|---|---|---|
value | string | The value of this option. |
className | string | Extra classes, merged with the component's own. |