Overview
Get Started
Components
- Accordion
- Alert Dialog
- Alert
- Autocomplete
- Avatar
- Badge
- Button Group
- Button
- Calendar
- Checkbox Group
- Checkbox
- Collapsible
- Combobox
- Command
- Dialog
- Field
- Form
- Input Group
- Input
- Kbd
- Label
- Menu
- Meter
- Navigation Menu
- Number Field
- Number InputNew
- OTP Field
- Pagination
- Popover
- Radio Group
- Scroll Area
- Select
- Sheet
- Sidebar
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Tooltip
Select your framework
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export function RadioGroupDemo() {
return (
<RadioGroup aria-labelledby="framework-label" defaultValue="next">
<div id="framework-label" className="font-medium text-sm">
Select your framework
</div>
<Label>
<Radio value="next" /> Next.js
</Label>
<Label>
<Radio value="vite" /> Vite
</Label>
<Label>
<Radio value="astro" /> Astro
</Label>
</RadioGroup>
);
}Installation
pnpm dlx @zbmui/cli@latest add radio-group
Usage
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";<RadioGroup defaultValue="next">
<Label>
<Radio value="next" /> Next.js
</Label>
<Label>
<Radio value="vite" /> Vite
</Label>
<Label>
<Radio value="astro" /> Astro
</Label>
</RadioGroup>Examples
Labeling a radio group
Label the group with aria-labelledby and a sibling label element:
<div id="storage-type-label">Storage type</div>
<RadioGroup aria-labelledby="storage-type-label">{/* ... */}</RadioGroup>An enclosing <label> is the simplest labeling pattern for each radio:
<label>
<Radio value="ssd" />
SSD
</label>Disabled
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export function RadioGroupDemo() {
return (
<RadioGroup aria-label="Framework" defaultValue="next">
<Label>
<Radio value="next" /> Next.js
</Label>
<Label>
<Radio disabled value="vite" /> Vite (disabled)
</Label>
<Label>
<Radio value="astro" /> Astro
</Label>
</RadioGroup>
);
}Description
Choose a subscription plan
Basic features for personal use.
Advanced tools for professionals.
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export function RadioGroupDemo() {
return (
<RadioGroup aria-labelledby="subscription-plan" defaultValue="free">
<div id="subscription-plan">Choose a subscription plan</div>
<div className="flex items-start gap-2">
<Radio id="free" value="free" />
<div className="flex flex-col gap-1">
<Label htmlFor="free">Free</Label>
<p className="text-muted-foreground text-xs">Basic features for personal use.</p>
</div>
</div>
<div className="flex items-start gap-2">
<Radio id="pro" value="pro" />
<div className="flex flex-col gap-1">
<Label htmlFor="pro">Pro</Label>
<p className="text-muted-foreground text-xs">Advanced tools for professionals.</p>
</div>
</div>
</RadioGroup>
);
}Card style
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export function RadioGroupDemo() {
return (
<RadioGroup aria-label="Notification method" defaultValue="email">
<Label className="flex items-start gap-2 rounded-lg border p-3 hover:bg-accent/50 has-data-checked:border-primary/48 has-data-checked:bg-accent/50">
<Radio value="email" />
<div className="flex flex-col gap-1">
<p>Email</p>
<p className="text-muted-foreground text-xs">Receive notifications via email.</p>
</div>
</Label>
<Label className="flex items-start gap-2 rounded-lg border p-3 hover:bg-accent/50 has-data-checked:border-primary/48 has-data-checked:bg-accent/50">
<Radio value="sms" />
<div className="flex flex-col gap-1">
<p>SMS</p>
<p className="text-muted-foreground text-xs">Receive notifications via text message.</p>
</div>
</Label>
</RadioGroup>
);
}