Radio Group
A composable, accessible RadioGroup component for modern React applications.
tsx
import { RadioGroup } from '@nofinite/nui';Interactive Preview
Loading preview...
A controlled/uncontrolled selection component that enables users to choose a single option from a set while preserving native radio behavior, accessibility semantics, keyboard navigation, and layout orientation control.
Implements a compound component architecture with context-driven state synchronization between RadioGroup and RadioGroup.Item.
Usage
Basic Usage
tsx
import { RadioGroup } from '@nofinite/nui';
<RadioGroup defaultValue="apple">
<RadioGroup.Item value="apple" />
<RadioGroup.Item value="banana" />
<RadioGroup.Item value="orange" />
</RadioGroup>;Controlled Usage
tsx
const [value, setValue] = useState('apple');
<RadioGroup value={value} onChange={setValue}>
<RadioGroup.Item value="apple" />
<RadioGroup.Item value="banana" />
</RadioGroup>;Horizontal Orientation
tsx
<RadioGroup orientation="horizontal" defaultValue="a">
<RadioGroup.Item value="a" />
<RadioGroup.Item value="b" />
<RadioGroup.Item value="c" />
</RadioGroup>Disabled Group
tsx
<RadioGroup disabled defaultValue="a">
<RadioGroup.Item value="a" />
<RadioGroup.Item value="b" />
</RadioGroup>RadioGroup.Item
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Unique option value |
disabled | boolean | false | Disable specific item |
id | string | auto-generated | Input id for label linking |
className | string | — | Custom styling |
Variants
tsx
<RadioGroup defaultValue="a" /> // Vertical (default)
<RadioGroup orientation="horizontal" /> // Horizontal
<RadioGroup disabled /> // Disabled
<RadioGroup value="a" /> // ControlledAvailable variants
vertical— Stacked layouthorizontal— Inline layoutdisabled— Non-interactive groupcontrolled— External state managementuncontrolled— Internal state management
Guidelines
- Use controlled mode for form libraries
- Prefer horizontal layout for small option sets
- Maintain consistent naming for grouping semantics
- Use disabled state to prevent invalid selections
States
| State | Description |
|---|---|
unchecked | Default state |
checked | Selected option |
hover | Pointer hover feedback |
focus-visible | Keyboard focus ring |
disabled | Non-interactive state |
Keyboard Interaction
| Key | Behavior |
|---|---|
Arrow keys | Navigate options within group |
Space | Select focused radio |
Tab | Move focus into/out of group |
Native browser radio semantics ensure automatic roving focus and selection behavior.
Accessibility
- Implements
role="radiogroup" - Uses native
<input type="radio">for full accessibility support - Automatic shared
nameattribute for grouping semantics - Supports
aria-orientation - Uses
aria-checkedstate synchronization - Focus-visible ring for keyboard navigation
- Compatible with
<label htmlFor>associations
Best Practices
Do
- Use consistent values across items
- Provide labels using
<label htmlFor> - Prefer controlled mode for form integration
- Group logically related options
- Use horizontal layout only for limited choices
Don’t
- Use radios for multi-select scenarios
- Leave items without accessible labels
- Mix controlled and uncontrolled patterns
- Overcrowd horizontal layouts
- Disable individual items without context
API Reference
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | — |
defaultValue | string | — | — |
onChange | ((value: string) => void) | — | — |
name | string | — | — |
disabled | boolean | false | — |
orientation | enum | vertical | — |