# Radio

## Usage

`Radio` represents a single option. It must be used inside a `RadioGroup`, which manages selection through `provide/inject`.

```vue
<script setup lang="ts">
import { Radio, RadioGroup } from '@astryx-vue/core/Radio'
import { shallowRef } from 'vue'

const size = shallowRef('md')
</script>

<template>
  <RadioGroup v-model="size" label="Size">
    <Radio value="sm" label="Small" />
    <Radio value="md" label="Medium" />
    <Radio value="lg" label="Large" />
  </RadioGroup>
</template>
```

## Examples

### Basic

Place Radio items inside RadioGroup. v-model binds the currently selected value.

```vue
<script setup lang="ts">
import { Radio, RadioGroup } from '@astryx-vue/core/Radio'
import { shallowRef } from 'vue'

const size = shallowRef('md')
</script>

<template>
  <div class="input-preview-grid">
    <RadioGroup v-model="size" label="Size">
      <Radio value="sm" label="Small" />
      <Radio value="md" label="Medium" />
      <Radio value="lg" label="Large" />
    </RadioGroup>
  </div>
</template>
```

### Disabled option

A single option can be disabled without affecting the rest of the group.

```vue
<script setup lang="ts">
import { RadioGroup } from '@astryx-vue/core/Radio'
import { shallowRef } from 'vue'

const selected = shallowRef('b')
</script>

<template>
  <div class="input-preview-grid">
    <RadioGroup v-model="selected" label="Disabled option" :options="[{ value: 'a', label: 'Available' }, { value: 'b', label: 'Unavailable', isDisabled: true }]" />
  </div>
</template>
```

## Keyboard interactions

Once focus enters a radio group, the options follow the browser's native radio keyboard behavior, so no extra key conventions are needed:

- Tab: focus the radio group. Focus lands on the currently selected option, and the whole group takes up a single stop in the tab order.
- Arrow keys: move the selection within the group.
- Space: select the option that currently has focus.

## Usage notes

A radio group is meant for choosing one option out of a small, mutually exclusive set. Once that set grows larger, the pattern stops working well.

- When there are only a few mutually exclusive options, a radio group lets the user see every choice at a glance.
- When there are more than about 7 options, a select control takes up less space and is easier to scan.

Whatever the number of options, always provide a group `label`: it is the accessible name for the whole radio group, and screen readers rely on it when announcing the options.

## Radio Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `string \| number` | — | Required. Option value. |
| `label` | `string` | — | Required. Visible label and accessible name. |
| `description` | `string` | — | Description shown below the label. |
| `id` | `string` | — | ID of the native input. Auto-generated when omitted. |
| `isDisabled` | `boolean` | `false` | Disable this option. |
| `isReadOnly` | `boolean` | `false` | Make this option read-only. |

## Events

- `change(value, event)`: fired when the user selects this option.

When Radio is used inside RadioGroup, RadioGroup coordinates the change events.

## Slots

- `labelIcon`: decorative icon before the label.

## Usage constraint

`Radio` depends on `RadioContext`. When used standalone, it falls back to a context-free state and renders a single radio button only.
Always use Radio as a child of RadioGroup or RadioList.
