Components
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Dialog
- EmptyNew
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input GroupNew
- KbdNew
- Label
- Menu
- Meter
- Number Field
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- SkeletonNew
- Slider
- SpinnerNew
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
Resources
Radio Group
A set of checkable buttons where no more than one of the buttons can be checked at a time.
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export default function Particle() {
return (
<RadioGroup defaultValue="next">
<Label>
<Radio value="next" /> Next.js
</Label>
<Label>
<Radio value="vite" /> Vite
</Label>
<Label>
<Radio value="astro" /> Astro
</Label>
</RadioGroup>
);
}
Installation
pnpm dlx shadcn@latest add @coss/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
For accessible labelling and validation, prefer using the Field component to wrap radio buttons. See the related example: Radio Group field.
Disabled
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export default function Particle() {
return (
<RadioGroup defaultValue="next">
<Label>
<Radio value="next" /> Next.js
</Label>
<Label>
<Radio disabled value="vite" /> Vite (disabled)
</Label>
<Label>
<Radio value="astro" /> Astro
</Label>
</RadioGroup>
);
}
With Description
Basic features for personal use.
Advanced tools for professionals.
import { Label } from "@/components/ui/label";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export default function Particle() {
return (
<RadioGroup defaultValue="r-1">
<div className="flex items-start gap-2">
<Radio id="r-1" value="r-1" />
<div className="flex flex-col gap-1">
<Label htmlFor="r-1">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="r-2" value="r-2" />
<div className="flex flex-col gap-1">
<Label htmlFor="r-2">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 default function Particle() {
return (
<RadioGroup defaultValue="r-1">
<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="r-1" />
<div className="flex flex-col gap-1">
<p className="text-sm leading-4">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="r-2" />
<div className="flex flex-col gap-1">
<p className="text-sm leading-4">SMS</p>
<p className="text-muted-foreground text-xs">
Receive notifications via text message.
</p>
</div>
</Label>
</RadioGroup>
);
}
Form Integration
"use client";
import * as React from "react";
import { Button } from "@/components/ui/button";
import { Field, FieldLabel } from "@/components/ui/field";
import { Fieldset, FieldsetLegend } from "@/components/ui/fieldset";
import { Form } from "@/components/ui/form";
import { Radio, RadioGroup } from "@/components/ui/radio-group";
export default function Particle() {
const [loading, setLoading] = React.useState(false);
const onSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
setLoading(true);
await new Promise((r) => setTimeout(r, 800));
setLoading(false);
alert(`Selected: ${formData.get("frameworks")}`);
};
return (
<Form className="max-w-[160px]" onSubmit={onSubmit}>
<Field
className="gap-4"
name="frameworks"
render={(props) => <Fieldset {...props} />}
>
<FieldsetLegend className="font-medium text-sm">
Frameworks
</FieldsetLegend>
<RadioGroup defaultValue="next">
<FieldLabel>
<Radio disabled={loading} value="next" /> Next.js
</FieldLabel>
<FieldLabel>
<Radio disabled={loading} value="vite" /> Vite
</FieldLabel>
<FieldLabel>
<Radio disabled={loading} value="astro" /> Astro
</FieldLabel>
</RadioGroup>
</Field>
<Button disabled={loading} type="submit">
Submit
</Button>
</Form>
);
}
Comparing with Radix / shadcn
If you’re already familiar with Radix UI and shadcn/ui, this guide highlights the small differences and similarities so you can get started with coss ui quickly.
Quick Checklist
- Use
Radiogoing forward;RadioGroupItemremains for legacy - If you used
asChildon parts, switch to therenderprop