When to use
- One choice from two to six options that people should see all at once: a drop-off preference, a billing interval.
- Options that need a sentence of explanation each, shown under the label with
description. - Choices with a price or a detail per option, such as delivery speeds or plans: use
RadioCards.
When not to use
- A long list of options: use a Select, or a Combobox when people know what they are looking for.
- A compact switch between a few short labels in a toolbar or header: use Segmented.
- Several options that can be on at once: use Checkboxes.
- A single on/off setting: use a Switch.
Installation
pnpm dlx shadcn add https://eased.dev/r/radio-group.jsonnpx shadcn add https://eased.dev/r/radio-group.jsonyarn dlx shadcn add https://eased.dev/r/radio-group.jsonbunx --bun shadcn add https://eased.dev/r/radio-group.jsonThe command adds Radio Group, everything it builds on and Eased’s tokens to your project.
Install the dependencies
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/reactAdd the Eased pieces it builds on
Copy each item’s files the same way, or install them with the CLI:
Copy the source into your project
components/eased/radio-group/radio-group.tsxTSX "use client";import { Radio as BaseRadio } from "@base-ui/react/radio";import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";import { useId, type ReactNode } from "react";import { Indicator, IndicatorGroup } from "../_primitives/indicator/indicator";type GroupProps<V extends string> = { /** The selected value (controlled). */ value?: V; /** The initially selected value (uncontrolled). */ defaultValue?: V; onValueChange?: (value: V) => void; /** Submits the value with a form under this name. */ name?: string; disabled?: boolean; required?: boolean; /** Accessible name, e.g. "Delivery". Or point `aria-labelledby` at a visible label. */ "aria-label"?: string; "aria-labelledby"?: string; className?: string; children: ReactNode;};export type RadioGroupProps<V extends string> = GroupProps<V>;/** * A list of radios. Base UI's RadioGroup supplies the behaviour: one tab stop, arrow keys * move and select, form submission and Field validation. */export function RadioGroup<V extends string>({ className = "", onValueChange, children, ...props }: RadioGroupProps<V>) { return ( <BaseRadioGroup<V> {...props} onValueChange={(v) => onValueChange?.(v)} className={`flex flex-col gap-1 ${className}`} > {children} </BaseRadioGroup> );}/** The 16px control itself: a ring that fills, and a dot that scales out from the centre. */function RadioControl({ className = "" }: { className?: string }) { return ( <span aria-hidden className={`flex size-4 shrink-0 items-center justify-center rounded-pill border border-line-strong bg-surface transition-colors duration-150 ease-standard group-data-checked:border-brand group-data-checked:bg-brand group-data-disabled:border-line group-data-disabled:bg-surface-sunken group-hover-fine:group-data-unchecked:border-text-muted ${className}`} > <span className="size-1.5 scale-50 rounded-pill bg-text-on-brand opacity-0 transition-[scale,opacity] duration-(--eased-duration-instant) ease-exit group-data-checked:scale-100 group-data-checked:opacity-100 group-data-checked:duration-(--eased-duration-spring-snappy) group-data-checked:ease-spring-snappy group-data-disabled:bg-text-disabled reduced:scale-100 reduced:duration-(--eased-duration-instant)!" /> </span> );}export type RadioProps<V extends string> = { value: V; /** The label. Clicking it selects the radio. */ children: ReactNode; /** Muted text under the label. */ description?: ReactNode; disabled?: boolean; className?: string;};/** One radio with its label (and optional description), aligned to the label's first line. */export function Radio<V extends string>({ value, children, description, disabled, className = "" }: RadioProps<V>) { const id = useId(); return ( <BaseRadio.Root value={value} disabled={disabled} aria-labelledby={`${id}-label`} aria-describedby={description ? `${id}-desc` : undefined} className={(state) => `group flex min-w-0 items-start gap-2.5 rounded-control-xs py-1.5 text-left select-none focus-ring ${ state.disabled ? "cursor-not-allowed" : "cursor-pointer" } ${className}` } > {/* 16px control centred on the 14px label's 20px first line. */} <span className="flex h-5 items-center"> <RadioControl /> </span> <span className="flex min-w-0 flex-col gap-0.5"> <span id={`${id}-label`} className="text-ui text-text group-data-disabled:text-text-disabled"> {children} </span> {description && ( <span id={`${id}-desc`} className="text-ui-sm text-text-muted text-pretty"> {description} </span> )} </span> </BaseRadio.Root> );}export type RadioCardsProps<V extends string> = GroupProps<V> & { /** Columns at full width; cards stack to one column under 360px of container. Default 1. */ columns?: 1 | 2 | 3;};const COLUMNS = { 1: "grid-cols-1", 2: "grid-cols-1 @min-[22rem]:grid-cols-2", 3: "grid-cols-1 @min-[30rem]:grid-cols-3" } as const;/** * Radio cards: the selected card's border is one highlight that travels between cards * on the snappy spring. Cards in a row share a height (`auto-rows-fr`), so the ring only * ever translates and never distorts. */export function RadioCards<V extends string>({ className = "", columns = 1, onValueChange, children, ...props }: RadioCardsProps<V>) { return ( <div className="@container w-full min-w-0"> <BaseRadioGroup<V> {...props} onValueChange={(v) => onValueChange?.(v)} className={`isolate grid auto-rows-fr gap-2 ${COLUMNS[columns]} ${className}`} > <IndicatorGroup>{children}</IndicatorGroup> </BaseRadioGroup> </div> );}export type RadioCardProps<V extends string> = { value: V; title: ReactNode; description?: ReactNode; /** Right-aligned detail on the title row, e.g. a price. */ meta?: ReactNode; /** A 16px icon before the title. */ icon?: ReactNode; disabled?: boolean; className?: string;};/** One card. The whole card is the hit target; the radio dot sits top-right as the affordance. */export function RadioCard<V extends string>({ value, title, description, meta, icon, disabled, className = "" }: RadioCardProps<V>) { const id = useId(); return ( <BaseRadio.Root value={value} disabled={disabled} aria-labelledby={`${id}-title`} aria-describedby={description ? `${id}-desc` : undefined} render={(htmlProps, state) => ( <span {...htmlProps}> {/* Three layers across all cards: fills, then the travelling ring, then every card's content, so the ring passes behind the text of the cards it crosses. */} {state.checked && <Indicator className="-inset-px z-1 rounded-[calc(var(--eased-radius-control)+1px)] border border-brand-line bg-brand-subtle" />} <span className="relative z-2 flex min-w-0 items-start gap-2.5"> {icon && <span className="flex h-5 shrink-0 items-center text-text-secondary [&_svg]:size-4">{icon}</span>} <span className="flex min-w-0 flex-1 flex-col gap-0.5"> <span className="flex min-w-0 items-baseline gap-2"> <span id={`${id}-title`} className="min-w-0 flex-1 truncate text-ui font-medium text-text group-data-disabled:text-text-disabled"> {title} </span> {meta && <span className="shrink-0 text-ui-sm text-text-secondary tabular-nums">{meta}</span>} </span> {description && ( <span id={`${id}-desc`} className="text-ui-sm text-text-muted text-pretty"> {description} </span> )} </span> <span className="flex h-5 items-center"> <RadioControl /> </span> </span> </span> )} className={(state) => `group relative flex min-w-0 flex-col justify-center rounded-control border border-line-subtle bg-surface p-3 text-left select-none transition-[color,background-color,border-color,box-shadow] duration-150 ease-standard focus-ring ${ state.disabled ? "cursor-not-allowed bg-surface-sunken" : state.checked ? "cursor-default" : "cursor-pointer hover-fine:border-line hover-fine:bg-surface-hover" } ${className}` } /> );}Keep the folder layout
The files import each other by relative path (
../lib/motion), so keep each one at the path shown, undercomponents/eased/.
Usage
import { Radio, RadioGroup } from "@/components/eased/radio-group/radio-group";export function DropOff() { return ( <RadioGroup aria-label="Drop-off" name="drop-off" defaultValue="door"> <Radio value="door">Leave it at the door</Radio> <Radio value="hand" description="We text you 10 minutes before we arrive."> Hand it to me </Radio> </RadioGroup> );}Examples
Radio cards
Each card is a whole hit target with a title, an optional price or detail in meta, and a description. The selected border travels between cards.
<RadioCards aria-label="Delivery speed" name="speed" value={speed} onValueChange={setSpeed}> <RadioCard value="standard" title="Standard" meta="Free" description="Arrives Fri, Oct 23" /> <RadioCard value="express" title="Express" meta="$12.00" description="Arrives Wed, Oct 21" /> <RadioCard value="overnight" title="Overnight" meta="$29.00" description="Tomorrow by 10am" /></RadioCards>A disabled option, explained
Say why an option is unavailable in its description rather than in a tooltip, which touch and keyboard users may never see.
<Radio value="hand" disabled={!express} description="Available with Express or Overnight."> Hand it to me</Radio>API reference
RadioGroup
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | The selected value (controlled). | |
defaultValue | string | The initially selected value (uncontrolled). | |
onValueChange | (value: string) => void | ||
name | string | Submits the value with a form under this name. | |
disabled | boolean | Disables every option. | |
required | boolean | ||
aria-label / aria-labelledby | string | Names the group. | |
className | string | "" | Appended to the group's classes. |
RadioCards
The same props as RadioGroup, plus:
| Prop | Type | Default | Description |
|---|---|---|---|
columns | 1 | 2 | 3 | 1 | Columns at full width. Cards stack to one column when the container is narrower than 22rem (2 columns) or 30rem (3 columns). |
Cards in a row share a height.
Radio
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | ||
children | ReactNode | The label. Clicking it selects the radio. | |
description | ReactNode | Muted text under the label. | |
disabled | boolean | ||
className | string | "" |
RadioCard
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | ||
title | ReactNode | The card's label; truncates to one line. | |
description | ReactNode | Muted text under the title. | |
meta | ReactNode | Right-aligned detail on the title row, such as a price. | |
icon | ReactNode | A 16px icon before the title. | |
disabled | boolean | ||
className | string | "" |
Keyboard
| Key | Action |
|---|---|
Tab | Moves focus into the group, to the selected option, then out of it. |
← → ↑ ↓ | Moves focus to the previous or next option and selects it. |
Space | Selects the focused option. |
Accessibility
- Base UI renders
role="radiogroup"androle="radio"witharia-checked; name the group witharia-labeloraria-labelledbypointing at a visible heading. - Each option is labelled by its label or title and described by its description, so the explanation is read with it.
- The whole row or card is the hit target, not just the 16px circle.
- With
name, a hidden input submits the value with a native form.
Motion
Selecting a radio fills its ring over 150ms and scales the dot out from half size at the centre on the snappy spring; the dot leaves in 100ms, faster than it came. On cards, the selected border and tint are one highlight that travels to the new card on the snappy spring, and redirects from wherever it is if you change your mind mid-flight. Because cards in a row share a height, it only ever moves and never stretches. Reduced motion shows the dot at full size with a 100ms fade, and the highlight jumps instead of travelling.
Notes for AI
Use RadioGroup with Radio for plain choices, and RadioCards with RadioCard when each option has a title, a price or a short detail. Always name the group, pass name inside a form, and put the reason for a disabled option in its description.
Do not mix Radio inside RadioCards or RadioCard inside RadioGroup: the card's travelling highlight needs the RadioCards wrapper. Do not add your own selected border or check icon to cards; the highlight and dot already show the state.
Related components
- Animated Segmented Control: a compact single choice between a few short labels.
- Animated Checkbox: when several options can be on at once.
- Animated Select: one choice from a long list, in a menu.