Files
2025-10-30 17:40:14 +01:00

98 lines
2.0 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Radio Group
description: A set of checkable buttons where no more than one of the buttons can be checked at a time.
links:
doc: https://base-ui.com/react/components/radio-group#api-reference
---
<ComponentPreview name="radio-group-demo" />
## Installation
<CodeTabs>
<TabsList>
<TabsTab value="cli">CLI</TabsTab>
<TabsTab value="manual">Manual</TabsTab>
</TabsList>
<TabsPanel value="cli">
```bash
npx shadcn@latest add @coss/radio-group
```
</TabsPanel>
<TabsPanel value="manual">
<Steps>
<Step>Install the following dependencies:</Step>
```bash
npm install @base-ui-components/react
```
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="radio-group" title="components/ui/radio-group.tsx" />
<Step>Update the import paths to match your project setup.</Step>
</Steps>
</TabsPanel>
</CodeTabs>
## Usage
```tsx
import { Label } from "@/components/ui/label"
import { Radio, RadioGroup } from "@/components/ui/radio-group"
```
```tsx
<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](/ui/docs/components/field#radio-group-field).
### Disabled
<ComponentPreview name="radio-group-disabled" />
### With Description
<ComponentPreview name="radio-group-with-description" />
### Card Style
<ComponentPreview name="radio-group-card" />
### Form Integration
<ComponentPreview name="radio-group-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 `Radio` going forward; `RadioGroupItem` remains for legacy
- If you used `asChild` on parts, switch to the `render` prop