|
| 1 | +--- |
| 2 | +title: Radio - Accessible Radio Button Controls |
| 3 | +meta: |
| 4 | +- name: description |
| 5 | + content: Headless radio button component for single-selection groups. Keyboard navigation, roving tabindex, and full ARIA compliance built-in. |
| 6 | +- name: keywords |
| 7 | + content: radio, radio button, form control, single-select, accessible, ARIA, Vue 3, headless |
| 8 | +features: |
| 9 | + category: Component |
| 10 | + label: 'E: Radio' |
| 11 | + level: 2 |
| 12 | + github: /components/Radio/ |
| 13 | +related: |
| 14 | + - /composables/selection/use-single |
| 15 | + - /components/providers/single |
| 16 | + - /components/forms/checkbox |
| 17 | +--- |
| 18 | + |
| 19 | +<script setup> |
| 20 | +import GroupExample from '@/examples/components/radio/group.vue' |
| 21 | +import GroupExampleRaw from '@/examples/components/radio/group.vue?raw' |
| 22 | +import MandatoryExample from '@/examples/components/radio/mandatory.vue' |
| 23 | +import MandatoryExampleRaw from '@/examples/components/radio/mandatory.vue?raw' |
| 24 | +</script> |
| 25 | + |
| 26 | +# Radio |
| 27 | + |
| 28 | +A headless radio button component for single-selection groups with keyboard navigation and roving tabindex. |
| 29 | + |
| 30 | +<DocsPageFeatures :frontmatter /> |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +Radio buttons must be used within a `Radio.Group`. Use `v-model` on the group to bind the selected value: |
| 35 | + |
| 36 | +<DocsExample file="group.vue" :code="GroupExampleRaw"> |
| 37 | + <GroupExample /> |
| 38 | +</DocsExample> |
| 39 | + |
| 40 | +## Anatomy |
| 41 | + |
| 42 | +```vue Anatomy playground |
| 43 | +<script setup lang="ts"> |
| 44 | + import { Radio } from '@vuetify/v0' |
| 45 | +</script> |
| 46 | +
|
| 47 | +<template> |
| 48 | + <Radio.Group> |
| 49 | + <Radio.Root> |
| 50 | + <Radio.Indicator /> |
| 51 | + </Radio.Root> |
| 52 | +
|
| 53 | + <Radio.Root> |
| 54 | + <Radio.Indicator /> |
| 55 | + </Radio.Root> |
| 56 | + </Radio.Group> |
| 57 | +
|
| 58 | + <!-- With form submission --> |
| 59 | + <Radio.Group> |
| 60 | + <Radio.Root> |
| 61 | + <Radio.Indicator /> |
| 62 | +
|
| 63 | + <Radio.HiddenInput /> |
| 64 | + </Radio.Root> |
| 65 | +
|
| 66 | + <Radio.Root> |
| 67 | + <Radio.Indicator /> |
| 68 | +
|
| 69 | + <Radio.HiddenInput /> |
| 70 | + </Radio.Root> |
| 71 | + </Radio.Group> |
| 72 | +</template> |
| 73 | +``` |
| 74 | + |
| 75 | +## Auto-Select First Option |
| 76 | + |
| 77 | +Radio groups are inherently mandatory—once a selection is made, it can only be changed, not cleared. Use `mandatory="force"` to automatically select the first non-disabled option on mount: |
| 78 | + |
| 79 | +<DocsExample file="mandatory.vue" :code="MandatoryExampleRaw"> |
| 80 | + <MandatoryExample /> |
| 81 | +</DocsExample> |
| 82 | + |
| 83 | +## Accessibility |
| 84 | + |
| 85 | +The Radio components handle all ARIA attributes automatically: |
| 86 | + |
| 87 | +- `role="radiogroup"` on the Group |
| 88 | +- `role="radio"` on each Root |
| 89 | +- `aria-checked` reflects checked state |
| 90 | +- `aria-disabled` when radio is disabled |
| 91 | +- `aria-required` for form validation (set on Group) |
| 92 | +- `aria-label` from the `label` prop |
| 93 | +- Roving `tabindex` - only the selected radio (or first if none) is tabbable |
| 94 | +- Space key selects the focused radio |
| 95 | +- Arrow keys navigate between radios |
| 96 | + |
| 97 | +For custom implementations, use `renderless` mode and bind the `attrs` slot prop to your element: |
| 98 | + |
| 99 | +```vue |
| 100 | +<template> |
| 101 | + <Radio.Root v-slot="{ attrs }" renderless> |
| 102 | + <div v-bind="attrs"> |
| 103 | + <!-- Custom radio visual --> |
| 104 | + </div> |
| 105 | + </Radio.Root> |
| 106 | +</template> |
| 107 | +``` |
| 108 | + |
| 109 | +## Keyboard Navigation |
| 110 | + |
| 111 | +Arrow keys provide circular navigation within a radio group: |
| 112 | + |
| 113 | +| Key | Action | |
| 114 | +|-----|--------| |
| 115 | +| `Space` | Select focused radio | |
| 116 | +| `ArrowUp` / `ArrowLeft` | Move to previous radio | |
| 117 | +| `ArrowDown` / `ArrowRight` | Move to next radio | |
| 118 | + |
| 119 | +Navigation automatically skips disabled items and wraps around. |
| 120 | + |
| 121 | +## Form Integration |
| 122 | + |
| 123 | +Set the `name` prop on `Radio.Group` to enable form submission for all radios in the group: |
| 124 | + |
| 125 | +```vue |
| 126 | +<template> |
| 127 | + <Radio.Group v-model="selected" name="size"> |
| 128 | + <Radio.Root value="small"> |
| 129 | + <Radio.Indicator /> |
| 130 | + Small |
| 131 | + </Radio.Root> |
| 132 | +
|
| 133 | + <Radio.Root value="large"> |
| 134 | + <Radio.Indicator /> |
| 135 | + Large |
| 136 | + </Radio.Root> |
| 137 | + </Radio.Group> |
| 138 | +</template> |
| 139 | +``` |
| 140 | + |
| 141 | +Each `Radio.Root` automatically renders a hidden native radio input with the shared `name` and its own `value`. |
| 142 | + |
| 143 | +For custom form integration, use `Radio.HiddenInput` explicitly: |
| 144 | + |
| 145 | +```vue |
| 146 | +<template> |
| 147 | + <Radio.Group> |
| 148 | + <Radio.Root value="a"> |
| 149 | + <Radio.Indicator /> |
| 150 | +
|
| 151 | + <Radio.HiddenInput name="custom" value="override" /> |
| 152 | + </Radio.Root> |
| 153 | + </Radio.Group> |
| 154 | +</template> |
| 155 | +``` |
| 156 | + |
| 157 | +<DocsApi /> |
0 commit comments