Form
Radio
Single native radio input. Use Radio Group for accessible keyboard-navigable groups.
Install
pnpm add @codefast/ui
Import path
@codefast/ui/radio
Examples
Single radios
Standalone radios sharing a name; the selected value is echoed below.
Size: Medium
Horizontal
Lay standalone radios out in a row.
Disabled option
Disable an individual choice while keeping it visible.
Anatomy
How the parts compose. Copy this skeleton and fill in the slots.
import { Radio } from "@codefast/ui/radio";
<Radio
name="size"
value="md"
checked={selected === "md"}
onValueChange={setSelected}
/>
API reference
Props for each part of the component. All native element props are also forwarded.
Radio
A single native radio input. Use Radio Group for managed groups.
| Prop | Type | Default | Description |
|---|---|---|---|
| checked / onValueChange | boolean / (value: string) => void | — | Controlled selected state; onValueChange fires with this radio’s value. |
| name | string | — | Radios sharing a name form one exclusive group. |
| value | string | — | The value submitted when this radio is chosen. |
Accessibility
Built to be keyboard-navigable and screen-reader friendly out of the box.
| Key | Function |
|---|---|
| Tab | Moves focus to the radio group. |
| Arrow+Down | Selects the next radio in the group. |
- Give every radio in a set the same name so only one can be selected.
- Pair each radio with a Label via matching id / htmlFor.
- For a managed, keyboard-navigable group, prefer Radio Group.
Guidelines
Conventions that keep usage consistent across an app.
Do
- Use Radio Group for most cases; reach for Radio for bespoke layouts.
- Always provide labels.
Don’t
- Don’t use radios for multi-select.
- Don’t forget the shared name attribute.