Radio group

Free

One choice among a few, as glass radio rows whose white bead springs in, with arrow keys that skip what can't be picked and a risky option set in the warning color.

npx shadcn@latest add https://pixilui.com/r/radio-group.json

Preview

The picked radio's white bead springs in.
Save

When to use

Use it when

  • One policy among two to five, each worth a second line: when an agent may spend, who can see a run.
  • A choice where one option carries a cost, marked with risk.

Use something else when

  • Several at once: use Checkbox.
  • Two or three short options that switch a view: use a segmented control.
  • Many options: use a select or a menu.

Installation

Terminal
npx shadcn@latest add https://pixilui.com/r/radio-group.json

Adds radio-group.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.

Usage

example.tsx
import { RadioGroup } from "@/components/pixilui/radio-group";

<RadioGroup onValueChange={onValueChange}>Save changes</RadioGroup>

The radio is 14px at every width; the words wrap beside it, the radio on the first line.

API reference

PropTypeDefault
valuestring | null–Controlled: the picked value.
defaultValuestring | nullnullUncontrolled: the value picked on the first render.
onValueChange(value: string) => void | Promise<void>–Runs with the new pick. Return a promise to save first: the group is aria-busy until it settles, and the pick goes back if it rejects.
namestring–A form field name: a hidden input carries the picked value.
disabledboolean–Disables every option.
aria-labelstring–The group's accessible name: the question the options answer.
childrenReactNode–RadioGroupItem rows.

Also takes every native <div> attribute except onChange, defaultValue, role, and a ref.

Keyboard

TabMoves into the group on the picked option (or the first that can be picked), and out again.
↓ →Picks the next option that can be picked, wrapping to the first.
↑ ←Picks the previous option that can be picked, wrapping to the last.

Accessibility

  • A role="radiogroup" named by its aria-label; each option is a button with role="radio" and aria-checked.
  • Each option is named by its label and described by its second line; the row is a label, so a click on the words picks it.
  • Roving tabindex: one option takes focus, and disabled options are skipped.
  • While a returned promise is pending the group is aria-busy.

Motion

  • Picked, the candy glass cross-fades in over 200ms and the white bead springs in over 260ms on the pop curve.
  • Press scales the radio to .9; hover previews a faint bead.
  • Reduced motion: no transitions, the bead shown at once.

PixilUI Pro opens soon. The first 20 licenses are $99.