Radio
A radio button component for selecting a single option from a group.
Overview
The Radio component provides a way for users to select a single option from a group of choices. It’s designed to work within the RadioGroup component for proper grouping and works seamlessly with the Field component for labels and error handling.
Basic Usage
Description
Radio can be used with or without labels, and supports standard states including disabled and error states.
With Label
With Error
Disabled
<div className="space-y-6 max-w-sm">
<Field>
<RadioGroup>
<Radio value="unlabeled">Unlabeled radio group</Radio>
<Radio value="option2">Option 2</Radio>
</RadioGroup>
</Field>
<Field>
<FieldLabel>With Label</FieldLabel>
<RadioGroup>
<Radio value="ipa">IPA</Radio>
<Radio value="stout">Stout</Radio>
<Radio value="pilsner">Pilsner</Radio>
</RadioGroup>
</Field>
<Field>
<FieldLabel>With Error</FieldLabel>
<RadioGroup aria-invalid={true}>
<Radio value="option1">This radio group has an error</Radio>
<Radio value="option2">Option 2</Radio>
</RadioGroup>
</Field>
<Field>
<FieldLabel>Disabled</FieldLabel>
<RadioGroup disabled defaultValue="disabled2">
<Radio value="disabled1">This radio is disabled</Radio>
<Radio value="disabled2">This is disabled and selected</Radio>
</RadioGroup>
</Field>
</div>Horizontal Layout
Description
Display radio buttons in a horizontal row by customizing the RadioGroup’s className.
<Fieldset
title="Serving Temperature"
subtitle="Select your preferred serving temperature">
<Field>
<RadioGroup defaultValue="cold" className="flex-row space-x-6 space-y-0">
<Radio value="cold">Cold</Radio>
<Radio value="cool">Cool</Radio>
<Radio value="cellar">Cellar Temp</Radio>
</RadioGroup>
</Field>
</Fieldset>Components
Radio
The individual radio button component.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | - | The value of this radio option |
| children | ReactNode | - | Label text for the radio button |
| className | string | - | Additional CSS class names |
| disabled | boolean | false | Disables the radio button (inherited from RadioGroup) |
RadioGroup
A container component for organizing multiple radio buttons.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| defaultValue | string | - | Initial selected value (uncontrolled) |
| value | string | - | Controlled selected value |
| disabled | boolean | false | Disables all radio buttons in the group |
| aria-invalid | boolean | false | Indicates validation error state for the group |
| className | string | - | Additional CSS class names for layout customization |
| children | ReactNode | - | Radio components to display |
Additional Features
- Validation States: Use
aria-invalidon RadioGroup to show error styling on all radios - Focus States: Automatic focus ring styling matching other form components
- Dark Mode: Fully themed with CSS custom properties
- Keyboard Navigation: Arrow keys navigate between options, Space selects
- Custom Layout: Use className to control spacing and direction (flex-row for horizontal)
Usage Notes
- Radio buttons should always be used within a RadioGroup
- Each Radio must have a unique
valueprop - Only one radio can be selected at a time within a group
- Use FieldLabel or Fieldset title for the group label
- The disabled state applies to all radios when set on RadioGroup
Accessibility
The Radio component follows accessibility best practices:
- Uses semantic HTML with proper ARIA attributes
- Supports keyboard navigation (Arrow keys to move, Space to select)
- Maintains proper focus styles for keyboard users
- Provides visual feedback for selected/unselected states
- Ensures sufficient color contrast for the radio indicator
When implementing radio buttons, ensure that:
- Radio groups have clear labels describing the choice
- Each radio option has descriptive text
- Related radios are grouped using RadioGroup
- Form validation messages are clearly associated with radio groups
- Only one radio can be selected at a time within a group