Radio Group
An accessible radio group component for single-select scenarios. Features arrow key navigation using the roving tabindex pattern and proper ARIA attributes.
Basic Usage
Simple radio group with arrow key navigation.
Selected: medium
import { useState } from 'react';
import { AccessibleRadioGroup } from '@a13y/react';
function Example() {
const [value, setValue] = useState('option1');
const options = [
{ value: 'option1', label: 'Option 1' },
{ value: 'option2', label: 'Option 2' },
{ value: 'option3', label: 'Option 3' }
];
return (
<AccessibleRadioGroup
legend="Select an option"
name="example"
options={options}
value={value}
onChange={setValue}
/>
);
}With Descriptions
Add descriptions to provide more context for each option.
RadioGroup Props
| Name | Type | Default | Description |
|---|---|---|---|
legend* | string | - | Label for the radio group (rendered as fieldset legend) |
name* | string | - | Name attribute for the radio inputs |
options* | RadioOption[] | - | Array of radio options |
value* | string | - | Currently selected value |
onChange* | (value: string) => void | - | Callback fired when selection changes |
disabled | boolean | false | Disable all radio buttons in the group |
error | string | - | Error message to display |
className | string | - | Optional CSS class for the fieldset |
RadioOption Props
| Name | Type | Default | Description |
|---|---|---|---|
value* | string | - | Value of the radio option |
label* | string | - | Label text for the radio button |
description | string | - | Optional description text shown below the label |
Keyboard Navigation
↓Move to next option
↑Move to previous option
SpaceSelect focused option
TabExit radio group
Accessibility Features
- ✓Uses
fieldsetandlegendfor semantic grouping - ✓Arrow key navigation with roving tabindex pattern
- ✓Each radio button properly associated with its label via
for/id - ✓Descriptions linked via aria-describedby
- ✓Error messages announced to screen readers