# Radio

Choose one option, move the selection with arrow keys, and submit it with a form.

Use radios for a short list of choices where only one can be picked, like a shipping speed or a plan. The group keeps one value and gives the whole list a single tab stop.

```angular-ts title="basic.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [Field, FieldLabel, Radio, RadioGroup, RadioIndicator],
  template: `
    <div uiField>
      <label uiFieldLabel>Shipping speed</label>
      <div uiRadioGroup defaultValue="standard">
        @for (speed of speeds; track speed.value) {
          <label data-slot="label">
            <button uiRadio [value]="speed.value">
              <span uiRadioIndicator></span>
            </button>
            {{ speed.label }}
          </label>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly speeds = [
    { value: "standard", label: "Standard" },
    { value: "express", label: "Express" },
    { value: "overnight", label: "Overnight" },
  ]
}

export { Example }
```

Choose Express, then use the arrow keys to move the selection between speeds.

## Installation

```bash
npm install @ui-sdk/angular @ui-sdk/core
```

## Composition

Use the following composition to build RadioGroup:

```text
uiRadioGroup
├── uiRadio
│   └── uiRadioIndicator
└── uiRadio
    └── uiRadioIndicator
```

Give each radio a `value` and wrap it with its text in a label. The group's value is the checked radio's value, and the indicator shows while its radio is checked.

## Usage

Import the parts and put them together:

```ts
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  selector: "app-example",
  imports: [Field, FieldLabel, Radio, RadioGroup, RadioIndicator],
  template: `
    <div uiField>
      <label uiFieldLabel>Shipping speed</label>
      <div uiRadioGroup defaultValue="standard">
        <label>
          <button uiRadio value="standard">
            <span uiRadioIndicator></span>
          </button>
          Standard
        </label>
        <label>
          <button uiRadio value="express">
            <span uiRadioIndicator></span>
          </button>
          Express
        </label>
      </div>
    </div>
  `,
})
class Example {}

export { Example }
```

The field's label names the group. Without a field, name it with `aria-label` or `aria-labelledby`. Without `defaultValue`, nothing starts checked and Tab enters on the first enabled radio.

## Description

Put each radio in its own `uiField` with a `uiFieldLabel` and `uiFieldDescription` when an option needs more explanation. That field connects both to its radio, while the outer field still names the group.

```angular-ts title="description.ts"
import { Component } from "@angular/core"
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [
    Field,
    FieldDescription,
    FieldLabel,
    Radio,
    RadioGroup,
    RadioIndicator,
  ],
  template: `
    <div uiField>
      <label uiFieldLabel>Email notifications</label>
      <div uiRadioGroup defaultValue="daily">
        @for (frequency of frequencies; track frequency.value) {
          <div uiField>
            <button uiRadio [value]="frequency.value">
              <span uiRadioIndicator></span>
            </button>
            <div data-slot="stack">
              <label uiFieldLabel>{{ frequency.label }}</label>
              <p uiFieldDescription>{{ frequency.description }}</p>
            </div>
          </div>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly frequencies = [
    {
      value: "instant",
      label: "Instantly",
      description: "An email right away.",
    },
    {
      value: "daily",
      label: "Daily digest",
      description: "One email each morning.",
    },
    {
      value: "weekly",
      label: "Weekly digest",
      description: "A summary every Monday.",
    },
  ]
}

export { Example }
```

Choose Weekly digest by its label. Each radio is also described by the line under it.

## Choice Card

Wrap an option's content in its label to make the whole card clickable. `:has([data-checked])` lets the card reflect the radio inside it.

```angular-ts title="choice-card.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [Field, FieldLabel, Radio, RadioGroup, RadioIndicator],
  template: `
    <div uiField>
      <label uiFieldLabel>Plan</label>
      <div uiRadioGroup defaultValue="hobby">
        @for (plan of plans; track plan.value) {
          <label data-slot="card">
            <span data-slot="stack">
              <span>{{ plan.label }}</span>
              <span data-slot="hint">{{ plan.description }}</span>
            </span>
            <button uiRadio [value]="plan.value">
              <span uiRadioIndicator></span>
            </button>
          </label>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly plans = [
    {
      value: "hobby",
      label: "Hobby",
      description: "Free for personal projects.",
    },
    {
      value: "pro",
      label: "Pro",
      description: "$20 per month for growing teams.",
    },
    {
      value: "enterprise",
      label: "Enterprise",
      description: "Custom pricing and support.",
    },
  ]
}

export { Example }
```

Click anywhere on the Pro card to choose it. Arrow keys move the selection between cards too.

## Fieldset and Legend

Use `uiFieldSet` and `uiFieldLegend` to describe a set of choices together. The legend names the group, so it needs no label of its own. Connect the group to the description with `aria-describedby`.

```angular-ts title="legend.ts"
import { Component } from "@angular/core"
import { FieldDescription, FieldLegend, FieldSet } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

let nextId = 0

@Component({
  imports: [
    FieldDescription,
    FieldLegend,
    FieldSet,
    Radio,
    RadioGroup,
    RadioIndicator,
  ],
  template: `
    <fieldset uiFieldSet>
      <legend uiFieldLegend [id]="\`\${id}-legend\`">Billing period</legend>
      <p uiFieldDescription [id]="\`\${id}-description\`">
        Yearly billing gets you two months free.
      </p>
      <div
        uiRadioGroup
        defaultValue="monthly"
        [aria-labelledby]="\`\${id}-legend\`"
        [aria-describedby]="\`\${id}-description\`"
      >
        @for (period of periods; track period.value) {
          <label data-slot="label">
            <button uiRadio [value]="period.value">
              <span uiRadioIndicator></span>
            </button>
            {{ period.label }}
            <span data-slot="hint">({{ period.price }})</span>
          </label>
        }
      </div>
    </fieldset>
  `,
})
class Example {
  readonly periods = [
    { value: "monthly", label: "Monthly", price: "$12 per month" },
    { value: "yearly", label: "Yearly", price: "$120 per year" },
  ]

  readonly id = `plan-${nextId++}`
}

export { Example }
```

Choose Yearly. The legend and the line under it describe both billing periods.

## Disabled

Set `disabled` on the group or on one radio. Disabled radios can't be focused or checked, and arrow keys skip them. A disabled fieldset disables the group too, and a disabled group submits nothing.

```angular-ts title="disabled.ts"
import { Component } from "@angular/core"
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [
    Field,
    FieldDescription,
    FieldLabel,
    Radio,
    RadioGroup,
    RadioIndicator,
  ],
  template: `
    <div data-slot="stack">
      <div uiField>
        <label uiFieldLabel>Theme</label>
        <p uiFieldDescription>Set by your organization.</p>
        <div uiRadioGroup defaultValue="light" disabled>
          @for (theme of themes; track theme.value) {
            <label data-slot="label">
              <button uiRadio [value]="theme.value">
                <span uiRadioIndicator></span>
              </button>
              {{ theme.label }}
            </label>
          }
        </div>
      </div>
      <div uiField>
        <label uiFieldLabel>Backups</label>
        <p uiFieldDescription>Hourly backups need the Pro plan.</p>
        <div uiRadioGroup defaultValue="daily">
          @for (backup of backups; track backup.value) {
            <label data-slot="label">
              <button
                uiRadio
                [value]="backup.value"
                [disabled]="backup.disabled"
              >
                <span uiRadioIndicator></span>
              </button>
              {{ backup.label }}
            </label>
          }
        </div>
      </div>
    </div>
  `,
})
class Example {
  readonly themes = [
    { value: "light", label: "Light" },
    { value: "dark", label: "Dark" },
    { value: "system", label: "System" },
  ]

  readonly backups = [
    { value: "hourly", label: "Hourly", disabled: true },
    { value: "daily", label: "Daily", disabled: false },
    { value: "weekly", label: "Weekly", disabled: false },
  ]
}

export { Example }
```

The Theme group is disabled. In Backups, Hourly is disabled, so the arrow keys move between Daily and Weekly.

## Read-Only

Set `readOnly` on the group to keep its value while still letting people focus and read the options. Arrow keys move focus without checking anything, and the value still submits with a form.

```angular-ts title="read-only.ts"
import { Component } from "@angular/core"
import { Field, FieldDescription, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [
    Field,
    FieldDescription,
    FieldLabel,
    Radio,
    RadioGroup,
    RadioIndicator,
  ],
  template: `
    <div uiField>
      <label uiFieldLabel>Your plan</label>
      <p uiFieldDescription>Ask an admin to change plans.</p>
      <div uiRadioGroup defaultValue="pro" readOnly>
        @for (plan of plans; track plan.value) {
          <label data-slot="label">
            <button uiRadio [value]="plan.value">
              <span uiRadioIndicator></span>
            </button>
            {{ plan.label }}
          </label>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly plans = [
    { value: "free", label: "Free" },
    { value: "pro", label: "Pro" },
    { value: "team", label: "Team" },
  ]
}

export { Example }
```

Click Team, or focus Pro and press the Down arrow. Pro stays checked.

## Controlled

Use `[(value)]` to own the value, and `(beforeValueChange)` for the reason. Call `$event.cancel()` in the callback to keep the current value. A [controller](#controller) from `createRadioGroupController()` checks a radio from anywhere, like the Choose Team button below. Create one controller per mounted group.

```angular-ts title="controlled.ts"
import { Component, signal } from "@angular/core"
import { useLog } from "./log"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import {
  createRadioGroupController,
  Radio,
  RadioGroup,
  RadioIndicator,
} from "@ui-sdk/angular/radio"

@Component({
  imports: [Field, FieldLabel, Radio, RadioGroup, RadioIndicator],
  template: `
    <div data-slot="stack">
      <div data-slot="controls">
        <button type="button" (click)="planGroup.setValue('team')">
          Choose Team
        </button>
      </div>
      <div uiField>
        <label uiFieldLabel>Plan</label>
        <div
          uiRadioGroup
          [(value)]="value"
          (beforeValueChange)="
            log(
              (plans.find((plan) => plan.value === $event.value)?.label ??
                'None') +
                ' (' +
                $event.reason +
                ')'
            )
          "
          [controller]="planGroup"
        >
          @for (plan of plans; track plan.value) {
            <label data-slot="label">
              <button uiRadio [value]="plan.value">
                <span uiRadioIndicator></span>
              </button>
              {{ plan.label }}
            </label>
          }
        </div>
      </div>
    </div>
  `,
})
class Example {
  readonly plans = [
    { value: "starter", label: "Starter" },
    { value: "pro", label: "Pro" },
    { value: "team", label: "Team" },
  ]

  readonly log = useLog()

  readonly planGroup = createRadioGroupController()

  readonly value = signal<string | null>("pro")
}

export { Example }
```

Choose Starter, then press Choose Team. The console logs each change and its reason.

See [State and Events](/docs/angular/state-and-events) for controlled state, cancellation and debugging.

## Form

Each radio renders a button with the `radio` role and a hidden native radio, so the group takes part in forms. Set `name` to submit the checked value; the group submits nothing without a name or a checked radio. `required` blocks submission until there's a choice, and a reset returns to `defaultValue`.

Set `form` to a form's id to join it from elsewhere on the page, as this group does.

```angular-ts title="form.ts"
import { Component } from "@angular/core"
import { useLog } from "./log"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

let nextId = 0

@Component({
  imports: [Field, FieldLabel, Radio, RadioGroup, RadioIndicator],
  template: `
    <div data-slot="stack">
      <div uiField>
        <label uiFieldLabel>Shipping speed</label>
        <div
          uiRadioGroup
          name="shipping"
          [form]="\`\${id}-checkout\`"
          required
          defaultValue="standard"
        >
          @for (speed of speeds; track speed.value) {
            <label data-slot="label">
              <button uiRadio [value]="speed.value">
                <span uiRadioIndicator></span>
              </button>
              {{ speed.label }}
              <span data-slot="hint">({{ speed.detail }})</span>
            </label>
          }
        </div>
      </div>
      <form
        data-slot="row"
        [id]="\`\${id}-checkout\`"
        (submit)="onSubmit($event)"
      >
        <button type="submit" data-variant="solid">Continue</button>
        <button type="reset">Reset</button>
      </form>
    </div>
  `,
})
class Example {
  readonly speeds = [
    { value: "standard", label: "Standard", detail: "Free, 5 to 7 days" },
    { value: "express", label: "Express", detail: "$9, 2 days" },
    { value: "overnight", label: "Overnight", detail: "$24, next day" },
  ]

  readonly log = useLog()

  readonly id = `plan-${nextId++}`

  onSubmit(event: SubmitEvent) {
    event.preventDefault()
    this.log(
      `Submitted shipping=${new FormData(event.currentTarget as HTMLFormElement).get("shipping")}`
    )
  }
}

export { Example }
```

Choose Express and press Continue. The console logs the submitted value, and Reset returns the choice to Standard.

## Validation

Put a required group in a [Field](/docs/angular/components/field) with a `uiFieldError`. Submitting without a choice shows the error under the group and moves focus to it. The [Forms guide](/docs/angular/forms) covers the shared field behavior.

```angular-ts title="invalid.ts"
import { Component } from "@angular/core"
import { useLog } from "./log"
import {
  Field,
  FieldDescription,
  FieldError,
  FieldLabel,
} from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [
    Field,
    FieldDescription,
    FieldError,
    FieldLabel,
    Radio,
    RadioGroup,
    RadioIndicator,
  ],
  template: `
    <form data-slot="stack" (submit)="onSubmit($event)">
      <div uiField>
        <label uiFieldLabel>Order updates</label>
        <p uiFieldDescription>Choose how we tell you about your orders.</p>
        <div uiRadioGroup name="updates" required>
          @for (channel of channels; track channel.value) {
            <label data-slot="label">
              <button uiRadio [value]="channel.value">
                <span uiRadioIndicator></span>
              </button>
              {{ channel.label }}
            </label>
          }
        </div>
        <div *uiFieldError>Choose how to get order updates.</div>
      </div>
      <div data-slot="row">
        <button type="submit" data-variant="solid">Save</button>
      </div>
    </form>
  `,
})
class Example {
  readonly channels = [
    { value: "email", label: "Email only" },
    { value: "sms", label: "SMS only" },
    { value: "both", label: "Email and SMS" },
  ]

  readonly log = useLog()

  onSubmit(event: SubmitEvent) {
    event.preventDefault()
    this.log(
      `Saved updates=${new FormData(event.currentTarget as HTMLFormElement).get("updates")}`
    )
  }
}

export { Example }
```

Press Save without a choice to see the error. Choose SMS only and save again; the console logs the saved value.

## Animation

The indicator has `data-starting-style` as it appears and `data-ending-style` while it leaves, and stays mounted until its exit finishes. Transition from those states:

```css
[data-slot="radio-indicator"] {
  transition:
    opacity 0.15s,
    scale 0.15s;

  &:is([data-starting-style], [data-ending-style]) {
    opacity: 0;
    scale: 0.5;
  }
}
```

`keepMounted` keeps the indicator showing while unchecked, with `data-unchecked`. Here it lets a hovered option preview its dot.

```angular-ts title="indicator.ts"
import { Component } from "@angular/core"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup, RadioIndicator } from "@ui-sdk/angular/radio"

@Component({
  imports: [Field, FieldLabel, Radio, RadioGroup, RadioIndicator],
  template: `
    <div uiField>
      <label uiFieldLabel>Theme</label>
      <div uiRadioGroup defaultValue="system">
        @for (theme of themes; track theme.value) {
          <label data-slot="label">
            <button uiRadio [value]="theme.value">
              <span uiRadioIndicator keepMounted></span>
            </button>
            {{ theme.label }}
          </label>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly themes = [
    { value: "light", label: "Light" },
    { value: "dark", label: "Dark" },
    { value: "system", label: "System" },
  ]
}

export { Example }
```

Hover Light to preview its dot, then choose it. The dot scales in on Light and out of System.

## Loop

Arrow keys wrap from the last radio to the first. Set `loop` to `false` to stop at the ends.

```angular-html
<div uiRadioGroup defaultValue="low" [loop]="false">...</div>
```

## Custom Rendering

The group, radio and indicator go on elements you write. Put `uiRadio` on the interactive element so its role, label and keyboard behavior stay connected, and read its state from a template reference: with `#radio="uiRadio"`, `radio.state().checked` says whether it's chosen. See [Parts and Composition](/docs/angular/parts-and-composition) for more.

```angular-ts title="render.ts"
import { Component } from "@angular/core"
import { LucideCheck } from "@lucide/angular"
import { Field, FieldLabel } from "@ui-sdk/angular/field"
import { Radio, RadioGroup } from "@ui-sdk/angular/radio"

let nextId = 0

@Component({
  imports: [Field, FieldLabel, Radio, RadioGroup, LucideCheck],
  template: `
    <div uiField>
      <label uiFieldLabel>Notify me about</label>
      <div uiRadioGroup defaultValue="mentions">
        @for (option of options; track option.value) {
          <button
            uiRadio
            #radio="uiRadio"
            [value]="option.value"
            [aria-labelledby]="\`\${id}-\${option.value}-label\`"
            [aria-describedby]="\`\${id}-\${option.value}-description\`"
          >
            <span data-slot="stack">
              <span [id]="\`\${id}-\${option.value}-label\`">{{
                option.label
              }}</span>
              <span
                data-slot="hint"
                [id]="\`\${id}-\${option.value}-description\`"
                >{{ option.description }}</span
              >
            </span>
            <svg
              lucideCheck
              [attr.data-checked]="radio.state().checked ? '' : null"
            ></svg>
          </button>
        }
      </div>
    </div>
  `,
})
class Example {
  readonly options = [
    {
      value: "all",
      label: "Everything",
      description: "Every message and update.",
    },
    {
      value: "mentions",
      label: "Mentions",
      description: "Only when someone mentions you.",
    },
    { value: "none", label: "Nothing", description: "Turn notifications off." },
  ]

  readonly id = `plan-${nextId++}`
}

export { Example }
```

Choose Nothing. Each radio renders a full-width button that shows a check from its state.

## Styling

Use `data-checked` and `data-unchecked` for the checked state, and `data-disabled`, `data-readonly` and `data-required` for the rest. The indicator gets the same state attributes as its radio, and the group gets `data-disabled`, `data-readonly` and `data-required`.

Each part has a `data-slot`, such as `radio`, and its state attributes are listed under [Data Attributes](#data-attributes).

## Data Attributes

### RadioGroup
`[data-slot="radio-group"]`

- `data-readonly`: Present when the group is read-only.
- `data-required`: Present when the group is required.
- `data-disabled`: Present when disabled, by its own prop, the group or a `<fieldset>`.

### Radio
`[data-slot="radio"]`

- `data-checked`: Present on the checked radio.
- `data-readonly`: Present when the group is read-only.
- `data-required`: Present when the group is required.
- `data-unchecked`: Present on radios that aren't checked.
- `data-disabled`: Present when disabled, by its own prop, the group or a `<fieldset>`.

### RadioIndicator
`[data-slot="radio-indicator"]`

- `data-checked`: Present on the checked radio.
- `data-readonly`: Present when the group is read-only.
- `data-required`: Present when the group is required.
- `data-unchecked`: Present on radios that aren't checked.
- `data-disabled`: Present when disabled, by its own prop, the group or a `<fieldset>`.
- `data-starting-style`: Present for the indicator's first frame. Style the state you animate from.
- `data-ending-style`: Present while the indicator animates out. Style the state you animate to.

## API Reference

Each option below is an input on the directive, and each callback an output. A change callback is two outputs: `(beforeValueChange)`, with the details and `cancel()`, then `(valueChange)` with the new value alone. Bind `value` with `[(value)]`.

### RadioGroup

- `value?` (`T | null`): The checked radio's value. Pass it to control the group. `null` checks nothing.
- `defaultValue?` (`T | null`): The radio checked at first, when uncontrolled. A form reset returns to it.
- `(beforeValueChange)`: Runs when a user or a form reset wants to change the value. `details.reason` says why, and `details.cancel()` stops it.
- `disabled?` (`boolean`): Disables every radio like native ones: they can't be focused or changed, and the value isn't submitted.
- `readOnly?` (`boolean`): Keeps the items focusable and the value submitted, but stops changes.
- `required?` (`boolean`): Blocks form submission until an item is checked, with the browser's own message.
- `name?` (`string`): The name the value submits under. Without one, the group submits nothing.
- `form?` (`string`): The id of a form to belong to, when the group isn't inside that form.
- `loop?` (`boolean`): Whether arrow keys wrap from the last item to the first.
- `controller?` (`{ getValue: () => T | null; setValue: (value: T | null, details?: Details) => boolean; focus: () => void; }`): Checks radios from anywhere. Create one with `createRadioGroupController()`.
- `debug?` (`boolean`): Logs every state change with its reason to the console, in development builds.

### Radio

- `value` (`string`): What the group's value becomes when this item is checked.
- `disabled?` (`boolean`): Skips the item, like a disabled native radio: arrow keys pass it and it can't be focused or checked.

### RadioIndicator

- `keepMounted?` (`boolean`): Whether the indicator stays in the page while its item is unchecked.

### State

What each part's `state()` signal holds.

- `value` (`string | null`): The checked item's value.
- `disabled` (`boolean`): Whether the group is disabled, by itself or by a `<fieldset>`.
- `readOnly` (`boolean`): Whether the group is read-only: arrow keys still move focus, but nothing changes the checked item.
- `required` (`boolean`): Whether a form won't submit until an item is checked.

- `checked` (`boolean`): Whether this item is checked.
- `disabled` (`boolean`): Whether this item is disabled, by itself, its group or a `<fieldset>`.
- `readOnly` (`boolean`): Whether the group is read-only.
- `required` (`boolean`): Whether the group is required.

- `checked` (`boolean`): Whether this item is checked.
- `disabled` (`boolean`): Whether this item is disabled, by itself, its group or a `<fieldset>`.
- `readOnly` (`boolean`): Whether the group is read-only.
- `required` (`boolean`): Whether the group is required.

### Reasons

`$event.reason` says why the checked value changed.

- `item-press` (`MouseEvent | KeyboardEvent`): A member of a collection was chosen: a menu item, a tab, a radio or a checkbox item.
- `list-navigation` (`KeyboardEvent`): Arrow, Home or End keys moved the selection, typing picked an item, or Ctrl or ⌘ with A selected every item of a listbox.
- `reset` (`none`): A form reset.
- `restore` (`none`): The browser restored state, like after going back, or a saved value was read back from storage.
- `imperative` (`none`): A controller or `api` call.

### Controller

Create one with `createRadioGroupController()` and pass it as `controller`.

Every write method takes an optional `{ reason, event }`, runs the change callback like a press, and returns `false` when the change is canceled.

- `getValue()` (`() => T | null`): The checked radio's value.
- `setValue(value, details?)` (`(value: T | null, details?: RadioGroupChangeOptions | undefined) => boolean`): Checks a radio, as a user would. Disabled radios and read-only groups ignore it.
- `focus()` (`() => void`): Moves focus to the checked radio, or the first one.

### Events

A `before` output emits `{ value, reason, event, cancel() }` before the change, and its plain output follows with the value alone. A bound `value` only updates when `(beforeValueChange)` wasn't canceled.

| Binding               | On             | Receives                                                                     |
| --------------------- | -------------- | ---------------------------------------------------------------------------- |
| `[(value)]`           | `uiRadioGroup` | The checked value                                                            |
| `(beforeValueChange)` | `uiRadioGroup` | `{ value, reason, cancel() }`: the checked value, and the [reason](#reasons) |

## Accessibility

Radio groups follow the [WAI-ARIA radio group pattern](https://www.w3.org/WAI/ARIA/apg/patterns/radio/), and behave like native radios that share a name. `uiRadio` renders a button with the `radio` role, and a hidden native radio that takes part in forms.

### Keyboard

| Key        | Does                                                                    |
| ---------- | ----------------------------------------------------------------------- |
| Tab        | Moves into the group, onto the checked radio or the first enabled one   |
| Arrow keys | Move to the next or previous radio and check it, skipping disabled ones |
| Space      | Checks the focused radio                                                |
| Enter      | Submits its form                                                        |

### Tested Behavior

Every line below is an automated test.

**Selection**

- Nothing is checked at first without a default value.
- Clicking an item checks it and unchecks the others.
- Clicking an item's label checks it.
- Clicking a disabled item does nothing.
- A change can be cancelled.

**Keyboard**

- Tab lands on the first item when nothing is checked.
- Tab lands on the checked item.
- Tab leaves the group after one stop.
- Space checks the focused item.
- ArrowDown and ArrowRight move to the next item and check it.
- ArrowUp and ArrowLeft move to the previous item and check it.
- Arrow keys skip disabled items.
- Arrow keys wrap at both ends.
- Enter never checks an item.
- Keys pressed in quick succession are never lost.
- Enter on an item submits the form.

**Read-only and disabled**

- A read-only group moves focus with arrow keys but checks nothing.
- A disabled group can't be focused or changed.
- Clicking a radio in a disabled group doesn't focus it.
- Clicking the label of a radio in a disabled group neither focuses nor checks it.

**Animation**

- The indicator animates in from its starting style.

Runs in React, Vue and web components.

In a field:

**With every radio enabled**

- Each radio is named by the label of its own field.
- The field around the group still names the group.
- Clicking a radio's label checks it and unchecks the others.
- The group keeps one tab stop.
- Arrow keys move between the radios and check them.

**A disabled radio**

- A disabled field around the first radio moves the tab stop to the next.
- Disabling the first radio after it renders moves the tab stop to the next.
- Enabling the first radio again gives it back the tab stop.

Runs in React, Vue and web components.

In right-to-left pages:

- ArrowLeft moves to the next radio and ArrowRight to the previous one.
- ArrowDown and ArrowUp keep their direction.

Runs in React, Vue and web components.
