Components / Forms

Radio Group18

One choice from a short list. The dot springs into the option you pick and wobbles as it lands. For long lists, use a Select instead.

RadioGroup · PlaygroundLive
Plan
orientation
JSX
<RadioGroup label="Plan">
  <Radio value="free" label="Free" />
  <Radio value="pro" label="Pro" />
  <Radio value="team" label="Team" />
</RadioGroup>

Usage

TSX
import { Radio, RadioGroup } from "plonk-ui";

export function Plan() {
  return (
    <RadioGroup label="Plan" name="plan" defaultValue="free">
      <Radio value="free" label="Free" />
      <Radio value="pro" label="Pro" />
    </RadioGroup>
  );
}

RadioGroup is a <fieldset> with a legend, and every Radio inside is a real <input type="radio"> sharing the group's name. The selected value is submitted with the form. A Radio has to be inside a RadioGroup.

Descriptions

Each option can have a description. Disable a single option with disabled, or the whole group with disabled on RadioGroup.

Radio Group · DescriptionsLive
Shipping

3–5 business days. Free.

Next day. $12.

Out of stock nearby.

TSX
import { Radio, RadioGroup } from "plonk-ui";

export default function Descriptions() {
  return (
    <RadioGroup label="Shipping" name="shipping" defaultValue="standard">
      <Radio
        value="standard"
        label="Standard"
        description="3–5 business days. Free."
      />
      <Radio value="express" label="Express" description="Next day. $12." />
      <Radio
        value="pickup"
        label="Pick up in store"
        description="Out of stock nearby."
        disabled
      />
    </RadioGroup>
  );
}

Controlled

Pass value and onValueChange to keep the selection in state. Use null for "nothing selected": undefined would make the group uncontrolled.

Radio Group · ControlledLive
Card size
Selected: md
import { useState } from "react";
import { Button, Radio, RadioGroup } from "plonk-ui";

export default function Controlled() {
  // null: controlled, nothing selected.
  const [size, setSize] = useState<string | null>("md");

  return (
    <div className="flex flex-col items-start gap-4">
      <RadioGroup
        label="Card size"
        orientation="horizontal"
        value={size}
        onValueChange={setSize}
      >
        <Radio value="sm" label="Small" />
        <Radio value="md" label="Medium" />
        <Radio value="lg" label="Large" />
      </RadioGroup>
      <div className="flex items-center gap-3">
        <Button size="sm" variant="neutral" onPress={() => setSize(null)}>
          Clear
        </Button>
        <span className="font-bold">Selected: {size ?? "nothing"}</span>
      </div>
    </div>
  );
}

Errors

error belongs to the group. It shows under the options, marks every option invalid, and shakes them once. Add required when an answer is mandatory.

Personalities

Sticker springs the dot in and wobbles the circle. Retro pops it in two steps, Comic punches it in fast with a big overshoot, and Arcade springs it in without the wobble.

Accessibility

  • A native radio group: Tab enters the group once, at the selected option, and arrow keys move and select.
  • The label is the fieldset's legend, so screen readers announce it when you enter the group.
  • description and error are linked to the group with aria-describedby.
  • orientation only changes the layout; the keys stay the same.

API

RadioGroup

All other <fieldset> props are passed through.

PropTypeDefaultDescription
namestring—Field name shared by all options. Generated when not set.
valuestring | null—Controlled selected value. Pass null for no selection; undefined makes the group uncontrolled.
defaultValuestring—Selected value on first render, when uncontrolled.
onValueChange(value: string) => void—Called with the option's value when it's selected.
requiredbooleanfalseOne option must be selected. Adds an asterisk to the label.
orientation"horizontal" | "vertical""vertical"Stacks options or lays them out in a wrapping row. Arrow keys work the same either way.
labelReactNode—Group label, rendered as the fieldset's legend.
descriptionReactNode—Help text under the label, read with the group.
errorReactNode—Error message for the whole group. Every option is marked invalid and the options shake once.
disabledboolean—Disables every option in the group.

Radio

All other <input> props are passed through.

PropTypeDefaultDescription
value*string—This option's value, sent with the form when selected.
labelReactNode—Visible label, linked to the option.
descriptionReactNode—Help text under the option's label.
disabledboolean—Disables this option only.