Radio

One option from a short visible set, for people and agents.

Source
$npx @dinachi/cli@latest add radio
defaultValue
disabled
readOnly

Usage

import { Radio, RadioGroup } from "@/components/ui/radio"

export function PlanPicker() {
  return (
    <RadioGroup aria-label="Plan" defaultValue="free">
      <label className="flex items-center gap-2">
        <Radio value="free" />
        Free
      </label>
      <label className="flex items-center gap-2">
        <Radio value="pro" />
        Pro
      </label>
    </RadioGroup>
  )
}

Examples

Three options with one chosen to start.
import { Radio, RadioGroup } from '@/components/ui/radio';

export function Example() {
  return (
    <RadioGroup defaultValue="comfortable">
      <label className="flex items-center gap-2">
        <Radio value="default" />
        <span className="text-sm font-medium">Default</span>
      </label>
      <label className="flex items-center gap-2">
        <Radio value="comfortable" />
        <span className="text-sm font-medium">Comfortable</span>
      </label>
      <label className="flex items-center gap-2">
        <Radio value="compact" />
        <span className="text-sm font-medium">Compact</span>
      </label>
    </RadioGroup>
  );
}

Notes

Radio labels

Wrap each Radio and its text in a <label>. Clicking the text picks the radio, and the agent reads the text as the option's name. Without a label it falls back to aria-label, then the value.

Built-in indicator

Radio already renders a RadioIndicator; do not add one inside it. The export is for custom radios built on the Base UI primitive.

API

valueValue
Controlled value.
defaultValueValue
Starting value when uncontrolled.
onValueChange
agent
(value, details) => void
Runs for people and agents. details.cancel() refuses the change.
aria-label
agent
string
Names the group, as does aria-labelledby. The agent reads it.
disabled
agent
boolean = false
Blocks people and agents.
readOnly
agent
boolean = false
Shows the value, refuses any change.
namestring
Submits the value with a form.
requiredboolean = false
Must have a value before the form submits.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as radio-group.

Reads

label

The group's aria-label or aria-labelledby.

value

The checked radio's label, or an empty string.

items

Every radio's label, in document order.

disabled

True when the whole group is blocked.

Actions

select("Compact")

Picks by label, then by value. A miss lists the options.

An agent's change runs through onValueChange. isAgentChange(details) is true for it, and details.cancel() refuses it; the agent is told the app refused. A disabled radio, a disabled group and readOnly refuse on their own.

await agent.act({
  steps: [{ ref: "radio-group", action: "select", args: ["Compact"] }],
})

Accessibility

  • The group is a radiogroup; each radio is a radio with aria-checked.
  • Name the group with aria-label or aria-labelledby. The agent reads the same name.
  • Enter does not check a radio; only Space and the arrow keys do.
  • A hidden input submits the value with a native form.