Radio

Picks one option from a few that are all worth seeing at once. Built on ui-sdk's RadioGroup: arrow keys move the choice, Tab leaves the group, and it submits with its form. Styled to match Checkbox.

BetaReady to use. Its API can still change in a minor release; the changelog says when.

import { RadioGroup, RadioGroupItem } from "@leap-crm/design-system";

Playground

Change a prop and the component follows. Its code is under Props.

Props

disabled

Best practices

When to use it, and the rules that apply in particular places.

GuidancePractice
DoUse it for one choice from a few options that are all worth seeing at once, like whether a matter is billed fixed fee or hourly.
DoName the group with aria-label or aria-labelledby, and each item with a Label pointing at its id, so pressing the label picks it.
DoLay two or three short options in a row with a flex class on the group, and keep longer ones stacked.
DoMark an invalid choice with aria-invalid on each item and say what to do in text, like Please choose a billing type. The red edge alone is colour alone.
Don'tUse it for a long list, like matter types or lawyers in a firm. Use Select, which keeps the options in a popup.
Don'tUse a single radio for yes or no. Use Checkbox in a form, or Switch for a setting that applies at once.

Props

RadioGroup also takes ui-sdk's value, defaultValue, onValueChange, disabled, readOnly, required, name, form and loop. RadioGroupItem takes value and disabled.

RadioGroup

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

RadioGroupItem

PropTypeDefaultDescription
classNamestring—Classes added to the root element, merged with its own. Tokens only.

Code

What the playground shows, ready to copy.

import { Label, RadioGroup, RadioGroupItem } from "@leap-crm/design-system";

<RadioGroup defaultValue="email" aria-label="Preferred contact">
  <RadioGroupItem id="email" value="email" />
  <Label htmlFor="email">Email</Label>
  <RadioGroupItem id="phone" value="phone" />
  <Label htmlFor="phone">Phone</Label>
</RadioGroup>

States

Unselected, selected, invalid (aria-invalid on each item), and a disabled group, unselected and selected.

In a row

Lay short options out in a row with a flex class on the group.

What the examples share

The imports and the scaffolding the examples above call. The scaffolding lives in this page, not in the library.

import { type ReactNode } from "react";

import { Label, RadioGroup, RadioGroupItem } from "@leap-crm/design-system";

function Option({
  id,
  value,
  children,
  disabled,
}: {
  id: string;
  value: string;
  children: ReactNode;
  disabled?: boolean;
}) {
  return (
    <div className="text-body flex items-center gap-2">
      <RadioGroupItem id={id} value={value} disabled={disabled} />
      <Label htmlFor={id}>{children}</Label>
    </div>
  );
}

Keyboard

The keys it answers to. Tab moves between components, arrows move within them.

KeysWhat they do
TabLands on the checked item, or the first when none is; the group is one stop.
Arrow keysMove between the radios and check them, skipping disabled ones and wrapping at both ends.
SpaceChecks the focused item.
EnterSubmits the form, and never checks an item.