# Radio group

A choice of one option from a few that are all in view.

```vue
<template>
  <NuiRadioGroup
    v-model="payment"
    label="Payment method"
    description="You can change it until the order ships"
  >
    <NuiRadio value="card">Card</NuiRadio>
    <NuiRadio value="transfer">Bank transfer</NuiRadio>
    <NuiRadio value="cash">On delivery</NuiRadio>
  </NuiRadioGroup>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { NuiRadio, NuiRadioGroup } from '@numior/kit';

const payment = ref('card');
</script>
```

Give every `NuiRadio` a `value`, and the `v-model` of the group holds the value of the checked
one.

## Installation

```ts
import { NuiRadio, NuiRadioGroup } from '@numior/kit';
```

## Usage

Lay the radios out in a row and change the size and the states of the group.

`Example.vue`

```vue
<template>
  <NuiRadioGroup v-model="delivery" :options="methods" />
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { NuiRadioGroup } from '@numior/kit';
import { DELIVERIES } from './orders';

const delivery = ref('courier');
const methods = Object.entries(DELIVERIES).map(([value, label]) => ({ value, label }));
</script>
```

`orders.ts`

```ts
export type OrderStatus = 'pending' | 'paid' | 'shipped' | 'delivered' | 'cancelled';
export type Payment = 'card' | 'transfer' | 'cash';
export type Delivery = 'courier' | 'pickup' | 'post';

export interface OrderLine {
  readonly sku: string;
  readonly name: string;
  readonly quantity: number;
  readonly price: number;
}

export interface Order {
  readonly id: number;
  readonly date: string;
  readonly customer: string;
  readonly city: string;
  readonly status: OrderStatus;
  readonly payment: Payment;
  readonly delivery: Delivery;
  readonly manager: string;
  readonly total: number;
  readonly lines: readonly OrderLine[];
}

export const ORDER_STATUSES: Record<OrderStatus, string> = {
  pending: 'Awaiting payment',
  paid: 'Paid',
  shipped: 'Shipped',
  delivered: 'Delivered',
  cancelled: 'Canceled',
};

export const PAYMENTS: Record<Payment, string> = {
  card: 'Card',
  transfer: 'Bank transfer',
  cash: 'On delivery',
};

export const DELIVERIES: Record<Delivery, string> = {
  courier: 'Courier',
  pickup: 'Pickup',
  post: 'Mail',
};

export const orders: readonly Order[] = [
  {
    id: 20401,
    date: '2026-09-16',
    customer: 'Peter Wolfe',
    city: 'Boston',
    status: 'delivered',
    payment: 'card',
    delivery: 'courier',
    manager: 'Anna Turner',
    total: 307,
    lines: [
      { sku: 'S-101', name: 'Oslo armchair', quantity: 1, price: 249 },
      { sku: 'X-507', name: 'Linen pillow', quantity: 2, price: 29 },
    ],
  },
  {
    id: 20402,
    date: '2026-09-17',
    customer: 'Lena Ortiz',
    city: 'Chicago',
    status: 'delivered',
    payment: 'card',
    delivery: 'pickup',
    manager: 'Anna Turner',
    total: 138,
    lines: [{ sku: 'L-401', name: 'Nord table lamp', quantity: 2, price: 69 }],
  },
  {
    id: 20403,
    date: '2026-09-18',
    customer: 'Tim Sayed',
    city: 'Denver',
    status: 'delivered',
    payment: 'transfer',
    delivery: 'courier',
    manager: 'Maria Kim',
    total: 507,
    lines: [
      { sku: 'T-201', name: 'Malmo desk', quantity: 1, price: 329 },
      { sku: 'S-104', name: 'Bergen chair', quantity: 2, price: 89 },
    ],
  },
  {
    id: 20404,
    date: '2026-09-19',
    customer: 'Vera Lane',
    city: 'Boston',
    status: 'cancelled',
    payment: 'card',
    delivery: 'courier',
    manager: 'Anna Turner',
    total: 180,
    lines: [{ sku: 'S-110', name: 'Loft stool', quantity: 4, price: 45 }],
  },
  {
    id: 20405,
    date: '2026-09-20',
    customer: 'Glen Nash',
    city: 'Austin',
    status: 'delivered',
    payment: 'cash',
    delivery: 'post',
    manager: 'Maria Kim',
    total: 175,
    lines: [
      { sku: 'X-501', name: 'Wool throw', quantity: 1, price: 59 },
      { sku: 'X-507', name: 'Linen pillow', quantity: 4, price: 29 },
    ],
  },
  {
    id: 20406,
    date: '2026-09-21',
    customer: 'Evan Porter',
    city: 'Seattle',
    status: 'shipped',
    payment: 'card',
    delivery: 'courier',
    manager: 'Anna Turner',
    total: 199,
    lines: [{ sku: 'H-301', name: 'Vik shelving unit', quantity: 1, price: 199 }],
  },
  {
    id: 20407,
    date: '2026-09-22',
    customer: 'Mary Cooper',
    city: 'Portland',
    status: 'shipped',
    payment: 'transfer',
    delivery: 'post',
    manager: 'Maria Kim',
    total: 416,
    lines: [
      { sku: 'L-408', name: 'Arc floor lamp', quantity: 1, price: 119 },
      { sku: 'L-412', name: 'Sphere pendant', quantity: 3, price: 99 },
    ],
  },
  {
    id: 20408,
    date: '2026-09-23',
    customer: 'Paul Hawkins',
    city: 'Boston',
    status: 'shipped',
    payment: 'card',
    delivery: 'courier',
    manager: 'Anna Turner',
    total: 368,
    lines: [
      { sku: 'H-305', name: 'Fjord dresser', quantity: 1, price: 299 },
      { sku: 'L-401', name: 'Nord table lamp', quantity: 1, price: 69 },
    ],
  },
  {
    id: 20409,
    date: '2026-09-24',
    customer: 'Olga Graham',
    city: 'Chicago',
    status: 'paid',
    payment: 'card',
    delivery: 'pickup',
    manager: 'Maria Kim',
    total: 139,
    lines: [{ sku: 'T-207', name: 'Tromso coffee table', quantity: 1, price: 139 }],
  },
  {
    id: 20410,
    date: '2026-09-25',
    customer: 'Sam Ellis',
    city: 'Denver',
    status: 'paid',
    payment: 'card',
    delivery: 'courier',
    manager: 'Anna Turner',
    total: 863,
    lines: [
      { sku: 'S-104', name: 'Bergen chair', quantity: 6, price: 89 },
      { sku: 'T-201', name: 'Malmo desk', quantity: 1, price: 329 },
    ],
  },
  {
    id: 20411,
    date: '2026-09-26',
    customer: 'Nina Hart',
    city: 'Austin',
    status: 'pending',
    payment: 'transfer',
    delivery: 'courier',
    manager: 'Maria Kim',
    total: 498,
    lines: [{ sku: 'S-101', name: 'Oslo armchair', quantity: 2, price: 249 }],
  },
  {
    id: 20412,
    date: '2026-09-27',
    customer: 'Alina Yusuf',
    city: 'Portland',
    status: 'pending',
    payment: 'card',
    delivery: 'pickup',
    manager: 'Anna Turner',
    total: 187,
    lines: [
      { sku: 'X-501', name: 'Wool throw', quantity: 2, price: 59 },
      { sku: 'L-401', name: 'Nord table lamp', quantity: 1, price: 69 },
    ],
  },
];
```

## Examples

### Keep an object in the model

Pass an object to `value`.

```vue
<template>
  <NuiRadioGroup
    v-model="warehouse"
    label="Shipping warehouse"
    :description="`The order is packed at ${warehouse.code}, ${warehouse.city}`"
  >
    <NuiRadio v-for="item in warehouses" :key="item.code" :value="item">
      {{ item.city }}
    </NuiRadio>
  </NuiRadioGroup>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { NuiRadio, NuiRadioGroup } from '@numior/kit';

interface Warehouse {
  readonly code: string;
  readonly city: string;
}

const main: Warehouse = { code: 'BOS-1', city: 'Boston' };
const warehouses: Warehouse[] = [main, { code: 'DEN-2', city: 'Denver' }];

const warehouse = ref(main);
</script>
```

The group matches a radio to the model by the key of its value, which is the JSON of the object
by default. When the object comes back from the server with changed fields, return its id from
`getKey`.

## Accessibility

The radios are native, so the arrow keys move the choice and a form submits the value under the
shared `name`. A screen reader reads the label, the hint and the error of the group when the
focus enters it.

`disabled` on the group turns off every radio, and on a `NuiRadio` only that one.

| Keys | Action |
| --- | --- |
| `ArrowDown` | Selects the next radio. |
| `ArrowUp` | Selects the previous radio. |
| `Space` | Selects the focused radio. |

## API

### NuiRadioGroup

```ts
import { NuiRadioGroup } from '@numior/kit';
```

#### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `name` | `string` |  | Name the selected value is submitted with in a form. |
| `orientation` | `NuiRadioGroupOrientation` | `"vertical"` | Lays out the radios in a column or a row. |
| `options` | `readonly NuiOption<T>[]` |  | Options to choose from. The radios are built from them instead of the slot. |
| `getKey` | `NuiOptionKey<NonNullable<T>>` |  | Function that returns the key of an object value; the selected radio is found by this key. Without it the JSON of the value is the key. |
| `id` | `string` |  | Id of the control. Defaults to the one from `NuiField` or is generated automatically. |
| `size` | `NuiSize` | `"md"` | Changes the size of the control: `sm`, `md` or `lg`. The theme density shifts the height of each size. |
| `disabled` | `boolean` |  | Disables the control. Inside `NuiField` it defaults to the field value. |
| `readonly` | `boolean` |  | Prevents changes to the value, which stays selectable and copyable. Inside `NuiField` it defaults to the field value. |
| `required` | `boolean` |  | Marks the control as required. Inside `NuiField` it defaults to the field value. |
| `invalid` | `boolean` |  | Shows the error state without a text. With `error` it turns on by itself. |
| `label` | `string` |  | Label of the control. Inside `NuiField` the field provides the label. |
| `description` | `string` |  | Hint below the control. Screen readers announce it with the control. |
| `error` | `string` |  | Error text below the control. Puts the control into the error state. |
| `reserveError` | `boolean` | `false` | Reserves space for the error so the form does not shift when it appears. |

#### Models

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `T` |  | Value of the selected radio. |

#### Slots

| Name | Slot props | Description |
| --- | --- | --- |
| `default` | `{}` | `NuiRadio` buttons. |
| `option` | `{ option: NuiOption<T>; }` | Label of a radio built from `options`. |

### NuiRadio

```ts
import { NuiRadio } from '@numior/kit';
```

#### Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` (required) | `T` |  | Value the group `v-model` receives. |
| `id` | `string` |  | Id of the radio. Generated automatically by default. |
| `disabled` | `boolean` |  | Disables one radio while the others in the group keep working. |

#### Slots

| Name | Slot props | Description |
| --- | --- | --- |
| `default` | `{}` | Label of the radio. |
