# Radio Group

> Radio group for React and shadcn, with plain radios or selectable cards whose selected border travels between them.

Radios whose dot scales out from the centre on a snappy spring, and radio cards whose selected border travels between cards. Base UI RadioGroup behaviour.

- Tier: Free (MIT)
- Interaction: Select
- Page: https://eased.dev/components/radio-group
- Installs: @base-ui/react
- Registry: https://eased.dev/r/radio-group.json

## Install

```bash
npx shadcn add https://eased.dev/r/radio-group.json
```

Radios and radio cards on Base UI's RadioGroup, which gives the group one tab stop, arrow keys that move and select, form submission through `name` and Field validation.

## When to use

- One choice from two to six options that people should see all at once: a drop-off preference, a billing interval.
- Options that need a sentence of explanation each, shown under the label with `description`.
- Choices with a price or a detail per option, such as delivery speeds or plans: use `RadioCards`.

## When not to use

- A long list of options: use a [Select](/components/select), or a [Combobox](/components/combobox) when people know what they are looking for.
- A compact switch between a few short labels in a toolbar or header: use [Segmented](/components/segmented).
- Several options that can be on at once: use [Checkboxes](/components/checkbox).
- A single on/off setting: use a [Switch](/components/switch).

## Usage

```tsx drop-off.tsx
import { Radio, RadioGroup } from "@/components/eased/radio-group/radio-group";

export function DropOff() {
  return (
    <RadioGroup aria-label="Drop-off" name="drop-off" defaultValue="door">
      <Radio value="door">Leave it at the door</Radio>
      <Radio value="hand" description="We text you 10 minutes before we arrive.">
        Hand it to me
      </Radio>
    </RadioGroup>
  );
}
```

## Examples

### Radio cards

Each card is a whole hit target with a title, an optional price or detail in `meta`, and a description. The selected border travels between cards.

```tsx
<RadioCards aria-label="Delivery speed" name="speed" value={speed} onValueChange={setSpeed}>
  <RadioCard value="standard" title="Standard" meta="Free" description="Arrives Fri, Oct 23" />
  <RadioCard value="express" title="Express" meta="$12.00" description="Arrives Wed, Oct 21" />
  <RadioCard value="overnight" title="Overnight" meta="$29.00" description="Tomorrow by 10am" />
</RadioCards>
```

### A disabled option, explained

Say why an option is unavailable in its description rather than in a tooltip, which touch and keyboard users may never see.

```tsx
<Radio value="hand" disabled={!express} description="Available with Express or Overnight.">
  Hand it to me
</Radio>
```

## API reference

### RadioGroup

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `string` | | The selected value (controlled). |
| `defaultValue` | `string` | | The initially selected value (uncontrolled). |
| `onValueChange` | `(value: string) => void` | | |
| `name` | `string` | | Submits the value with a form under this name. |
| `disabled` | `boolean` | | Disables every option. |
| `required` | `boolean` | | |
| `aria-label` / `aria-labelledby` | `string` | | Names the group. |
| `className` | `string` | `""` | Appended to the group's classes. |

### RadioCards

The same props as `RadioGroup`, plus:

| Prop | Type | Default | Description |
|---|---|---|---|
| `columns` | `1 \| 2 \| 3` | `1` | Columns at full width. Cards stack to one column when the container is narrower than 22rem (2 columns) or 30rem (3 columns). |

Cards in a row share a height.

### Radio

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `string` | | |
| `children` | `ReactNode` | | The label. Clicking it selects the radio. |
| `description` | `ReactNode` | | Muted text under the label. |
| `disabled` | `boolean` | | |
| `className` | `string` | `""` | |

### RadioCard

| Prop | Type | Default | Description |
|---|---|---|---|
| `value` | `string` | | |
| `title` | `ReactNode` | | The card's label; truncates to one line. |
| `description` | `ReactNode` | | Muted text under the title. |
| `meta` | `ReactNode` | | Right-aligned detail on the title row, such as a price. |
| `icon` | `ReactNode` | | A 16px icon before the title. |
| `disabled` | `boolean` | | |
| `className` | `string` | `""` | |

## Keyboard

| Key | Action |
|---|---|
| `Tab` | Moves focus into the group, to the selected option, then out of it. |
| `←` `→` `↑` `↓` | Moves focus to the previous or next option and selects it. |
| `Space` | Selects the focused option. |

## Accessibility

- Base UI renders `role="radiogroup"` and `role="radio"` with `aria-checked`; name the group with `aria-label` or `aria-labelledby` pointing at a visible heading.
- Each option is labelled by its label or title and described by its description, so the explanation is read with it.
- The whole row or card is the hit target, not just the 16px circle.
- With `name`, a hidden input submits the value with a native form.

## Motion

Selecting a radio fills its ring over 150ms and scales the dot out from half size at the centre on the snappy spring; the dot leaves in 100ms, faster than it came. On cards, the selected border and tint are one highlight that travels to the new card on the snappy spring, and redirects from wherever it is if you change your mind mid-flight. Because cards in a row share a height, it only ever moves and never stretches. Reduced motion shows the dot at full size with a 100ms fade, and the highlight jumps instead of travelling.

## Notes for AI

Use `RadioGroup` with `Radio` for plain choices, and `RadioCards` with `RadioCard` when each option has a title, a price or a short detail. Always name the group, pass `name` inside a form, and put the reason for a disabled option in its `description`.

Do not mix `Radio` inside `RadioCards` or `RadioCard` inside `RadioGroup`: the card's travelling highlight needs the `RadioCards` wrapper. Do not add your own selected border or check icon to cards; the highlight and dot already show the state.

## Related

- [Segmented](/components/segmented): a compact single choice between a few short labels.
- [Checkbox](/components/checkbox): when several options can be on at once.
- [Select](/components/select): one choice from a long list, in a menu.

## Example

`components/eased/radio-group/radio-group-demo.tsx`

```tsx
"use client";

import { useId, useState } from "react";
import { DemoFrame } from "../lib/demo-frame";
import { Radio, RadioCard, RadioCards, RadioGroup } from "./radio-group";

type Speed = "standard" | "express" | "overnight";
type DropOff = "door" | "hand";

const usd = new Intl.NumberFormat("en-US", { style: "currency", currency: "USD" });

const SPEEDS: { value: Speed; title: string; description: string; price: number }[] = [
  { value: "standard", title: "Standard", description: "Arrives Fri, Oct 23 – Tue, Oct 27", price: 0 },
  { value: "express", title: "Express", description: "Arrives Wed, Oct 21", price: 12 },
  { value: "overnight", title: "Overnight", description: "Tomorrow by 10am if you order in 2h 14m", price: 29 },
];

export function RadioGroupDemo() {
  const dropOffLabel = useId();
  const [speed, setSpeed] = useState<Speed>("express");
  const [dropOff, setDropOff] = useState<DropOff>("door");
  const handOff = speed !== "standard";
  const chooseSpeed = (next: Speed) => {
    setSpeed(next);
    if (next === "standard") setDropOff("door");
  };
  const price = SPEEDS.find((s) => s.value === speed)!.price;

  return (
    <DemoFrame title="Delivery" meta={price === 0 ? "Free" : usd.format(price)}>
      <div className="flex min-h-0 flex-1 flex-col gap-5 overflow-y-auto p-4">
        <RadioCards aria-label="Delivery speed" name="speed" value={speed} onValueChange={chooseSpeed}>
          {SPEEDS.map((s) => (
            <RadioCard
              key={s.value}
              value={s.value}
              title={s.title}
              description={s.description}
              meta={s.price === 0 ? "Free" : usd.format(s.price)}
            />
          ))}
        </RadioCards>

        <div className="flex flex-col gap-1">
          <p id={dropOffLabel} className="text-ui-sm font-medium text-text">
            Drop-off
          </p>
          <RadioGroup<DropOff> aria-labelledby={dropOffLabel} name="drop-off" value={dropOff} onValueChange={setDropOff}>
            <Radio value="door">Leave it at the door</Radio>
            <Radio
              value="hand"
              disabled={!handOff}
              description={handOff ? "We text you 10 minutes before we arrive." : "Available with Express or Overnight."}
            >
              Hand it to me
            </Radio>
          </RadioGroup>
        </div>
      </div>
    </DemoFrame>
  );
}
```
