# Radio Group

## Usage

`RadioGroup` is a container for mutually exclusive options. It provides name, selected value, and selection handling to child `Radio` items 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

RadioGroup manages the selected state of child Radio items.

```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

Options in the array or Radio children can be disabled individually.

```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 and accessibility

`RadioGroup` turns a set of mutually exclusive options into a single radio group, so assistive technology reads it as one control rather than a handful of unrelated buttons. The semantics and attributes below are handled by the component for you.

- The whole group renders as one container with `role="radiogroup"`, which screen readers announce with radio group semantics.
- `aria-labelledby` links the container to its label, so a group `label` is required — it is the accessible name of the whole group.
- The group sets `aria-invalid` automatically when it is in an error state.
- Setting `isRequired` shows the required hint and enables native required validation.

For the keyboard, every option in the group shares one `name`, so the browser treats them as a native radio group: pressing `Tab` moves into the group and lands on the selected option, and the arrow keys then move between options.

## Usage notes

These two notes help you choose between `RadioGroup` and [RadioList](/en/components/radio-list). Both solve the same problem — picking one value from a group of mutually exclusive options — and they differ only in how much control you get over the option layout.

- Use `RadioGroup` with `Radio` children when you need a custom option layout or rendering.
- Use [RadioList](/en/components/radio-list) when the options are simple and array-based and you do not need to customize the layout.

## RadioGroup Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `v-model` | `string \| number` | — | Required. Currently selected value. |
| `label` | `string` | — | Required. Accessible name of the group. |
| `id` | `string` | — | ID of the group container. Auto-generated when omitted. |
| `name` | `string` | — | Shared name for the radios. Auto-generated when omitted. |
| `options` | `RadioOption[]` | — | Array of options. Alternative to the default slot. |
| `width` | `number \| string` | — | Component width. Numbers are treated as px. |
| `description` | `string` | — | Description shown below the label. |
| `isLabelHidden` | `boolean` | `false` | Hide the visual label while keeping the accessible name. |
| `isDisabled` | `boolean` | `false` | Disable the entire group. |
| `isReadOnly` | `boolean` | `false` | Make the entire group read-only. |
| `isRequired` | `boolean` | `false` | Show required indicator and enable native required validation. |
| `isOptional` | `boolean` | `false` | Show optional indicator. Takes precedence over isRequired. |
| `optionalLabel` | `string` | `'Optional'` | Text for the optional indicator. |
| `requiredLabel` | `string` | `'Required'` | Text for the required indicator. |
| `status` | `FieldStatusInput` | — | Status type, message, and message ID. |
| `statusVariant` | `'attached' \| 'detached' \| 'tooltip'` | `'detached'` | Where to display the status message. |
| `labelIcon` | `Component` | — | Decorative icon before the label. |
| `labelTooltip` | `string` | — | Tooltip shown next to the label. |

## Status

`status` has these fields:

- `type`: `'error'`, `'warning'`, or `'success'`.
- `message`: message text.
- `messageId`: message ID.

The default `statusVariant` is `detached`, so the message appears below the group.

## Events

- `update:modelValue(value)`: emitted after the selected value changes.
- `change(value, event)`: fired after the model updates.

`event` is a cancellable `RadioChangeEvent`.
`event.detail.originalEvent` keeps the native event.

## Slots

- `default`: Radio children. Alternative to `options`.
- `labelIcon`: decorative icon before the label. Overrides the `labelIcon` prop.

## Template ref

- `element`: `HTMLDivElement | null`.

## Native attributes

`class` and `style` are applied to the outer wrapper.
Unrecognized native attributes and listeners are forwarded to the group container.
