codefast/ui

Command Palette

Search for a command to run...

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.

PropTypeDefaultDescription
checked / onValueChangeboolean / (value: string) => voidControlled selected state; onValueChange fires with this radio’s value.
namestringRadios sharing a name form one exclusive group.
valuestringThe value submitted when this radio is chosen.

Accessibility

Built to be keyboard-navigable and screen-reader friendly out of the box.

KeyFunction
TabMoves focus to the radio group.
Arrow+DownSelects 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.