<!-- generated by scripts/gen-docs.mjs from docs/system/radio-group.md. Edit the source and rerun. -->
# RadioGroup

## Description
Picks one of two to six choices that are each shown with their words, and sends the pick with the form when it is saved.

`import { RadioGroup, RadioGroupItem, Radio } from "@/components/cobalt/ui/radio-group"`, source `registry/cobalt/ui/radio-group.tsx`, status `ready-with-gaps`.
Foundation: `Base UI RadioGroup and Radio`. Traps checked: `trap/field-label`, `trap/label-unbound`, `trap/field-error-link`, `trap/field-keeps-input`, `trap/select-empty-value`, `trap/control-height`, `trap/focus-ring-shape`, `trap/hover-beats-focus`, `trap/disabled-still-hovers`, `trap/list-dead-gap`, `trap/weight-shift`, `trap/toggle-switch-submit`, `trap/icon-optical-align`.

Where each trap is answered: `trap/field-label` and `trap/label-unbound` in `rule/radio-group-is-named` and Accessibility, each choice is a `<label>` around its radio and the group takes `aria-labelledby`; `trap/field-error-link` in `rule/radio-group-error-is-linked`; `trap/field-keeps-input`, the value is the group's own state and survives a failed submit; `trap/select-empty-value` in `rule/radio-group-none-is-a-choice`; `trap/control-height` in Tokens, a row is at least 38px, the menu row's height; `trap/focus-ring-shape` in States, the outline is drawn round the 16px mark and is never clipped, since the row has no overflow; `trap/hover-beats-focus`, the row's hover fill and the mark's outline stack; `trap/disabled-still-hovers`, a disabled row drops its hover fill; `trap/list-dead-gap`, rows sit 2px apart and each row is all target; `trap/weight-shift`, a chosen row keeps its weight; `trap/toggle-switch-submit` in When not to use, a choice that acts at once is a SegmentedControl; `trap/icon-optical-align`, the mark sits in a box one line tall, so it centres on the first line at any text size.

The mark is round. D38 keeps `rounded-full` for a switch, an avatar, a radio mark and a thin progress bar; the radio is on that list because the circle is how every platform says "one of these", and a rounded square beside the 4px checkbox reads as a checkbox. Recorded in `docs/system/decisions.md` and `docs/system/radius.md`.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `RadioGroup`: a `role="radiogroup"` with one tab stop, arrow keys that move and check, `name` and a hidden input per radio for the form, `value`, `defaultValue`, `onValueChange`, `disabled`, `required`, `readOnly`; `Radio.Root` and `Radio.Indicator` | `variant`: `rows`, a column of 38px rows with the menu row's 12px corner and the `--hover` fill, and `inline`, choices side by side that wrap; `RadioGroupItem`, the mark, the name and an optional `description` in one `<label>`, which inside a `Field` is Base UI's `Field.Item`, so each radio keeps an id of its own while the Field's `FieldLabel`, description, error and `invalid` reach the group (Base UI's RadioGroup registers with the Field; without the item every radio took the Field's one control id); the mark, 16px round with the checkbox's `--control-edge`, filled with `--primary` and a 6px dot in `--primary-foreground` when chosen, red edge inside an `aria-invalid` group; the mark in a box one line tall so it sits on the first line |

## Examples
Three cancellation policies as rows under one legend, each with the refund it gives.

Real uses, 0 call sites (`rg -n "<RadioGroup\b" app registry --glob '!registry/cobalt/ui/*'`): `SegmentedControl` renders Base UI's own `RadioGroup` inside the ui folder, which this count leaves out; the source apps hand-roll three groups (`docs/research/2026-10-17-coverage.md`, row 6).

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/radio-group/default.tsx` | default | Three cancellation policies as rows under one legend, each with the refund it gives |
| `docs/system/examples/radio-group/default.tsx` | variant=rows | Full-width choices with a line of detail |
| `docs/system/examples/radio-group/variant-inline.tsx` | variant=inline | Three short choices side by side |
| Not applicable: the checked choice in every example | state:checked | The accent fill and the dot |
| Not applicable: reached with Tab on any example | state:focus-visible | The outline round the checked mark |
| `docs/system/examples/radio-group/state-disabled.tsx` | state:disabled | One choice disabled with the reason in its detail line, and a whole group disabled with the reason in its legend |
| `docs/system/examples/radio-group/state-invalid.tsx` | state:invalid | No choice yet on a required group, as after a submit: the marks in red and the Field's error tied to the group until one is chosen |
| `docs/system/examples/radio-group/in-card.tsx` | composition:Card | Alert timing in a card of settings, saved with the card's button |

Example: Three cancellation policies as rows under one legend, each with the refund it gives (`docs/system/examples/radio-group/default.tsx`)

```tsx
import { useId } from "react";

import { RadioGroup, RadioGroupItem } from "@/components/cobalt/ui/radio-group";

export default function Example() {
  const legend = useId();
  return (
    <RadioGroup
      render={<fieldset />}
      aria-labelledby={legend}
      name="policy"
      defaultValue="moderate"
      className="w-full max-w-sm min-w-0"
    >
      <legend id={legend} className="mb-2 text-sm font-medium">
        Cancellation policy
      </legend>
      <RadioGroupItem value="flexible" description="Full refund up to 24 hours before check-in.">
        Flexible
      </RadioGroupItem>
      <RadioGroupItem value="moderate" description="Full refund up to 5 days before check-in.">
        Moderate
      </RadioGroupItem>
      <RadioGroupItem value="strict" description="Half refund up to 7 days before check-in.">
        Strict
      </RadioGroupItem>
    </RadioGroup>
  );
}
```

Example: Alert timing in a card of settings, saved with the card's button (`docs/system/examples/radio-group/in-card.tsx`)

```tsx
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/cobalt/ui/card";
import { RadioGroup, RadioGroupItem } from "@/components/cobalt/ui/radio-group";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call: it answers after a second.
const saveAlerts = () => new Promise<void>((resolve) => setTimeout(resolve, 1000));

export default function Example() {
  const saving = useAction(saveAlerts);
  return (
    <Card className="w-full max-w-sm">
      <CardHeader>
        <CardTitle id="alerts-title">Filing alerts</CardTitle>
        <CardDescription>When we tell you about new filings from advisers you watch.</CardDescription>
      </CardHeader>
      <CardContent>
        <RadioGroup aria-labelledby="alerts-title" name="alerts" defaultValue="daily">
          <RadioGroupItem value="instant" description="An email for each filing.">
            As they arrive
          </RadioGroupItem>
          <RadioGroupItem value="daily" description="One email at 8:00 with the day's filings.">
            Daily digest
          </RadioGroupItem>
          <RadioGroupItem value="weekly" description="One email on Monday morning.">
            Weekly digest
          </RadioGroupItem>
        </RadioGroup>
      </CardContent>
      <CardFooter>
        <StateButton
          status={saving.status}
          pendingLabel="Saving"
          successLabel="Saved"
          failureLabel="Not saved"
          onClick={() => void saving.run()}
        >
          Save alerts
        </StateButton>
      </CardFooter>
    </Card>
  );
}
```

## Variants

### variant
- `rows`: a column of full-width rows, for choices with a line of detail. Used at 0 call sites; 4 groups in 4 examples (`docs/system/examples/radio-group/default.tsx:9`, `docs/system/examples/radio-group/state-disabled.tsx:11`, `docs/system/examples/radio-group/state-invalid.tsx:12`, `docs/system/examples/radio-group/in-card.tsx:19`).
- `inline`: two to four short choices in a row that wraps, for words of one or two each. Used at 0 call sites; 2 examples (`docs/system/examples/radio-group/variant-inline.tsx:14`, `docs/system/examples/radio-group/state-disabled.tsx:27`).

Example: Full-width choices with a line of detail (`docs/system/examples/radio-group/default.tsx`)

```tsx
import { useId } from "react";

import { RadioGroup, RadioGroupItem } from "@/components/cobalt/ui/radio-group";

export default function Example() {
  const legend = useId();
  return (
    <RadioGroup
      render={<fieldset />}
      aria-labelledby={legend}
      name="policy"
      defaultValue="moderate"
      className="w-full max-w-sm min-w-0"
    >
      <legend id={legend} className="mb-2 text-sm font-medium">
        Cancellation policy
      </legend>
      <RadioGroupItem value="flexible" description="Full refund up to 24 hours before check-in.">
        Flexible
      </RadioGroupItem>
      <RadioGroupItem value="moderate" description="Full refund up to 5 days before check-in.">
        Moderate
      </RadioGroupItem>
      <RadioGroupItem value="strict" description="Half refund up to 7 days before check-in.">
        Strict
      </RadioGroupItem>
    </RadioGroup>
  );
}
```

Example: Three short choices side by side (`docs/system/examples/radio-group/variant-inline.tsx`)

```tsx
import { useId } from "react";

import { RadioGroup, RadioGroupItem } from "@/components/cobalt/ui/radio-group";

export default function Example() {
  const legend = useId();
  return (
    <RadioGroup
      render={<fieldset />}
      aria-labelledby={legend}
      name="room"
      defaultValue="entire"
      variant="inline"
      className="min-w-0"
    >
      <legend id={legend} className="mb-2 text-sm font-medium">
        Room type
      </legend>
      <RadioGroupItem value="entire">Entire place</RadioGroupItem>
      <RadioGroupItem value="private">Private</RadioGroupItem>
      <RadioGroupItem value="shared">Shared</RadioGroupItem>
    </RadioGroup>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| unchecked | the choice is not the value | press the row, or arrow to it | the empty ring, `aria-checked="false"` | test |
| checked | the choice is the value | pick another | the filled mark with its dot, `aria-checked="true"`, `data-checked` | test |
| hover | pointer over a row, under `(hover: hover)` | press to pick | in `rows`, the row's `--hover` fill; `inline` has none | by hand |
| focus-visible | Tab into the group, or an arrow key | move with the arrows, which also pick | the shared 2px outline round the mark | by hand |
| disabled | `disabled` on the group or on one item | nothing; the arrows skip a disabled item | half opacity on the row, the not-allowed cursor, `data-disabled` | test |
| invalid | `aria-invalid` on the group | pick a choice | the marks' red edge and the linked error text | by hand |
| empty | no `value` and no `defaultValue` | pick one | every mark empty; the first enabled radio takes Tab | by hand |

Example: One choice disabled with the reason in its detail line, and a whole group disabled with the reason in its legend (`docs/system/examples/radio-group/state-disabled.tsx`)

```tsx
import { useId } from "react";

import { RadioGroup, RadioGroupItem } from "@/components/cobalt/ui/radio-group";

export default function Example() {
  const payout = useId();
  const currency = useId();
  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <RadioGroup render={<fieldset />} aria-labelledby={payout} name="payout" defaultValue="monthly" className="min-w-0">
        <legend id={payout} className="mb-2 text-sm font-medium">
          Payout schedule
        </legend>
        <RadioGroupItem value="monthly" description="On the first business day of each month.">
          Monthly
        </RadioGroupItem>
        <RadioGroupItem value="weekly" disabled description="Needs a verified bank account.">
          Weekly
        </RadioGroupItem>
      </RadioGroup>
      <RadioGroup
        render={<fieldset />}
        aria-labelledby={currency}
        name="currency"
        defaultValue="usd"
        variant="inline"
        disabled
        className="min-w-0"
      >
        <legend id={currency} className="mb-2 text-sm font-medium">
          Payout currency, set by your organisation
        </legend>
        <RadioGroupItem value="usd">US dollars</RadioGroupItem>
        <RadioGroupItem value="eur">Euros</RadioGroupItem>
      </RadioGroup>
    </div>
  );
}
```

Example: No choice yet on a required group, as after a submit: the marks in red and the Field's error tied to the group until one is chosen (`docs/system/examples/radio-group/state-invalid.tsx`)

```tsx
import { useId, useState } from "react";

import { Field, FieldError } from "@/components/cobalt/ui/field";
import { RadioGroup, RadioGroupItem } from "@/components/cobalt/ui/radio-group";

export default function Example() {
  const legend = useId();
  const [guest, setGuest] = useState<string | null>(null);
  return (
    <Field className="w-full max-w-sm">
      <RadioGroup
        render={<fieldset />}
        aria-labelledby={legend}
        name="guests"
        required
        value={guest}
        onValueChange={(value) => setGuest(value as string)}
        className="min-w-0"
      >
        <legend id={legend} className="mb-2 text-sm font-medium">
          Who is staying
        </legend>
        <RadioGroupItem value="me">Only me</RadioGroupItem>
        <RadioGroupItem value="group">Me and others</RadioGroupItem>
        <RadioGroupItem value="other">Someone else</RadioGroupItem>
      </RadioGroup>
      <FieldError reserve>{guest === null ? "Choose who is staying, so the host knows whose name to expect." : ""}</FieldError>
    </Field>
  );
}
```

### State precedence
- Checked and hover: both show. The row fill sits behind the filled mark.
- Checked and disabled: both show. The filled mark at half opacity says what was chosen.
- Disabled and hover: disabled wins. The row keeps no fill and shows the not-allowed cursor.
- Invalid and checked: Not applicable: the host clears `aria-invalid` once a choice is made.
- Focus-visible and hover: both show. The outline round the mark stays while the row fills.
- Empty and checked: Not applicable: a group has a value or has none.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| unchecked to checked and back | input | `duration-press` on `--curve` | background-color, border-color | the same colour change |
| pointer over a row | input | `duration-press` on `--curve` | background-color | the same colour change |

## Props

<!-- Props generated from registry/cobalt/ui/radio-group.tsx with TypeScript by scripts/props-table.mjs -->
### RadioGroup

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `variant?` | `"inline" \| "rows"` | `"rows"` | `rows` for a column of full-width choices, `inline` for two to four short words in a row. |

Also accepts every native `<div>` attribute; from Base UI: `defaultValue`, `disabled`, `form`, `inputRef`, `name`, `onValueChange`, `readOnly`, `render`, `required`, `value`.

### Radio

No props of its own.

Also accepts every native `<span>` attribute; from Base UI: `disabled`, `inputRef`, `nativeButton`, `readOnly`, `render`, `required`, `value`.

### RadioGroupItem

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  | The choice's name. |
| `value` | `any` |  | The value this choice gives the group. |
| `description?` | `ReactNode` |  | One line under the name, such as what the choice costs or changes. |
| `disabled?` | `boolean` |  |  |

Also accepts every native `<label>` attribute.

Notes only; gen-docs writes the table.
- `variant` on `RadioGroup`: `rows` (default) or `inline`.
- `description` on `RadioGroupItem`: one line under the name.
- `disabled` on `RadioGroupItem` or on the group.
- `value`, `defaultValue`, `onValueChange`, `name` and `required` are Base UI's, on the group.

## Usage

### When to use
- A form choice of one out of two to six, where each choice needs its words in view, such as a cancellation policy or how often alerts arrive.
- A choice with a line of detail that helps pick, such as what each plan costs.

### When not to use
- Two to four options that change the view at once, with nothing to save. Use SegmentedControl instead.
- More than six options, or options you find by typing. Use Select or Combobox instead.
- One choice that is on or off. Use Checkbox instead, or Switch when it acts at once.
- Several choices may be picked. Use a column of Checkbox rows instead.

### Rules
- `rule/radio-group-is-named`: When a `RadioGroup` renders, name it with `aria-labelledby` pointing at a visible heading or legend, instead of leaving the name to the choices, because a screen reader says the group's name once as you Tab in and the choices alone do not say what is being chosen. Evidence: app 6/6 groups in the examples carry `aria-labelledby` (`docs/system/examples/radio-group/default.tsx:11`, `docs/system/examples/radio-group/variant-inline.tsx:11`); principle wcag: 1.3.1 Info and Relationships. Check: review; a11y scan of the page.
  - Don't: `<RadioGroup name="policy"><RadioGroupItem value="flexible">Flexible</RadioGroupItem></RadioGroup>`
  - Do: `<RadioGroup render={<fieldset />} aria-labelledby={legend} name="policy"><legend id={legend}>Cancellation policy</legend>`
- `rule/radio-group-error-is-linked`: When a `RadioGroup` is invalid, set `aria-invalid` on the group and `aria-describedby` to the error's id, instead of a red line under it alone, because the red edge is drawn from `aria-invalid` and the error is read only when it is linked. Evidence: single use docs/system/examples/radio-group/state-invalid.tsx:12, measured `aria-invalid="true"` and `aria-describedby` set to the FieldError on the group in the showcase (Playwright, 2026-10-17); principle wcag: 3.3.1 Error Identification. Check: review; test `field.test.tsx` "each radio of a group in a Field keeps an id of its own" for the Field form.
  - Don't: `<RadioGroup aria-labelledby="guests-label">` with a `<p className="text-destructive">` beside it
  - Do: the group inside a `Field` with a `FieldError`, which sets `aria-invalid` and `aria-describedby` itself: `<Field><RadioGroup render={<fieldset />} aria-labelledby={legend}>…</RadioGroup><FieldError>Choose who is staying.</FieldError></Field>`
- `rule/radio-group-none-is-a-choice`: When a choice is optional, add a `RadioGroupItem` for none, such as "No alerts", instead of starting with nothing checked, because Base UI gives no way to uncheck a radio once checked. Evidence: principle platform: a radio group cannot return to no value by keyboard or pointer; principle heuristic: user control and freedom. Check: review of every optional group.
  - Don't: `<RadioGroup aria-labelledby="alerts">` with three digests and no way back
  - Do: `<RadioGroupItem value="off">No alerts</RadioGroupItem>` as the first choice
- `rule/radio-group-applies-on-save`: When a choice should take effect at once, use `SegmentedControl` instead of a `RadioGroup`, and when a `RadioGroup` is used, save it with the form's button, because a radio in a form reads as a pending answer and nothing tells the person it was saved. Evidence: single use docs/system/examples/radio-group/in-card.tsx:32; person D39. Check: review.
  - Don't: `<RadioGroup onValueChange={(v) => api.savePolicy(v)}>`
  - Do: `<RadioGroup name="alerts">` with `<StateButton status={saving.status}>Save alerts</StateButton>`

### Content
- Follows `rule/writing-field-label-noun`.
- `rule/radio-group-description-one-line`: When a `RadioGroupItem` has a `description`, write one sentence of at most 60 characters that says what the choice does, such as "Full refund up to 5 days before check-in.", instead of repeating the name, because the description is the reason to pick and a second sentence wraps the row past two lines at 390px. Evidence: app 8/8 descriptions in the examples are one sentence under 60 characters (`docs/system/examples/radio-group/default.tsx:19`, `docs/system/examples/radio-group/in-card.tsx:20`); measured a 59px row with one line of detail at 390px, `.design-system/evidence/radio-group/measure.json`. Check: review.
  - Don't: `<RadioGroupItem value="moderate" description="Moderate policy">Moderate</RadioGroupItem>`
  - Do: `<RadioGroupItem value="moderate" description="Full refund up to 5 days before check-in.">Moderate</RadioGroupItem>`

### Anti-slop
- `rule/radio-group-not-styled-buttons`: When one of several choices is picked in a form, use `RadioGroup` instead of a row of `Button`s or `Pill`s with an `aria-pressed` you toggle by hand, because buttons give each choice its own tab stop and no arrow keys, and the form gets no value. Evidence: principle platform: the radio group pattern is one tab stop with arrow keys; measured 1 arrow press moves and checks, `.design-system/evidence/radio-group/measure.json`. Check: review.
  - Don't: `{policies.map((p) => <Button key={p} variant={policy === p ? "default" : "secondary"} onClick={() => setPolicy(p)}>{p}</Button>)}`
  - Do: `<RadioGroup aria-labelledby="policy-label" value={policy} onValueChange={setPolicy}>`
- `rule/radio-group-round-mark-only-here`: When you need the radio's round mark outside a `RadioGroupItem`, render `Radio` instead of a `rounded-full` span, because the round mark is reserved for the radio, the switch, the avatar and the thin progress bar (D38) and a hand-drawn circle has no role or keyboard. Evidence: person D38; single use registry/cobalt/ui/radio-group.tsx:54. Check: review.
  - Don't: `<span className="size-4 rounded-full border" />`
  - Do: `<Radio value="flexible" aria-label="Flexible" />`

### Limits
- `rule/radio-group-max-choices`: When a choice has more than 6 options, use `Select` or `Combobox` instead, because six rows with a line of detail stand 6 x 59px, 354px, which fills most of a 390x844 screen before the form's other fields. Evidence: measured a 59px row with one line of detail at 390px, `.design-system/evidence/radio-group/measure.json`. Check: review, with the option count in the PR.
  - Don't: `<RadioGroup>` with 12 time zones
  - Do: `<Combobox items={zones}>`
- `rule/radio-group-inline-max-four`: When the `inline` variant holds more than 4 choices or a choice over 20 characters, use `rows` instead, because at 320px the worst-case inline group wraps to 4 lines and the choices no longer read as one row. Evidence: measured 4 lines for the 6-choice inline group at 320px, `.design-system/evidence/radio-group/measure.json`. Check: probe /stress/radio-group?data=worst.
  - Don't: `<RadioGroup variant="inline">` with six choices
  - Do: `<RadioGroup variant="rows">` with six choices

## Accessibility
Rests on Base UI `RadioGroup` and `Radio`: a `radiogroup` with one tab stop, and each radio inside a native `<label>`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the group | focuses the checked radio, or the first enabled one when none is checked | that radio | by hand |
| ArrowDown or ArrowRight | a radio | moves to the next enabled radio and checks it | that radio | by hand |
| ArrowUp or ArrowLeft | a radio | moves to the previous enabled radio and checks it | that radio | by hand |
| Space | a radio | checks it | the radio | by hand |
| Tab | a radio | leaves the group | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| group | radiogroup | `aria-labelledby` or `aria-label` | `aria-invalid`, `aria-describedby`, `aria-disabled`, `aria-required` | the name and the number of choices as you enter | a11y scan |
| radio | radio | the label's text: the name, then the description | `aria-checked`, `aria-disabled` | the name, "radio button", checked or not, its position | test |
| hidden input | none | none | `name` and the value | nothing; it carries the form value | test |

## Tokens
| Part | State | Token |
|---|---|---|
| row | rows | 38px at least, `--r-xl` |
| row | hover | `--hover` |
| mark | unchecked | `--control-edge`, `rounded-full`, 16px |
| mark | checked | `--primary`, the dot in `--primary-foreground` |
| mark | invalid | `--destructive` edge |
| description | all | `--muted-foreground` |
| row and mark | disabled | opacity 50 percent |

A row with one line of detail measures 59px at 390px, and the mark 16px (`.design-system/evidence/radio-group/measure.json`).

## Related
- SegmentedControl: two to four choices that change the view at once.
- Select: one of up to 10 options in a compact trigger.
- Combobox: one of a long list, found by typing.
- Checkbox: one choice that is on or off.
- Card: the surface a settings group sits on.
- Pill: one flat choice on or off, such as a filter.
- Toggle: keeps one tool pressed or not.
- EmojiPicker: finds an emoji by name or group and picks it, with a keyboard grid, a recent row and skin tones.
- Reactions: the emoji people reacted with under a message, each a toggle with its count, and a button to add one.
