Skip to content
EMBOSS
Docs menu

Radio Group

Recessed circular wells where the selected option seats an embossed accent pin; arrow keys rove between options.

@emboss/radio-group

Installation

pnpm dlx shadcn@latest add @emboss/radio-group

Usage

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

export function Example() {
  return (
    <RadioGroup defaultValue="48" aria-label="Sample rate">
      <RadioGroupItem value="44.1" aria-label="44.1 kHz" />
      <RadioGroupItem value="48" aria-label="48 kHz" />
    </RadioGroup>
  );
}

API reference

RadioGroup

PropTypeDefaultDescription
value / defaultValue / onValueChangestring / string / (value) => voidControlled and uncontrolled selection.
disabledbooleanfalseDisables the whole group.

RadioGroupItem

PropTypeDefaultDescription
valuestringThe option this item represents.
Data attributeDescription
data-checked / data-uncheckedReflects the selection for styling.

Keyboard

KeysAction
ArrowUpArrowDownMoves selection between options.
SpaceSelects the focused option.

Source

View source — radio-group.tsx
radio-group.tsx
"use client";

import { Radio } from "@base-ui/react/radio";
import { RadioGroup as BaseRadioGroup } from "@base-ui/react/radio-group";
import { cn } from "@/lib/utils";

export type RadioGroupProps = React.ComponentProps<typeof BaseRadioGroup>;

/**
 * A set of recessed circular wells; the selected option seats an embossed
 * accent pin. Arrow keys rove between options.
 *
 * @example
 * <RadioGroup defaultValue="48k" aria-label="Sample rate">
 *   <RadioGroupItem value="44.1k" aria-label="44.1 kHz" />
 *   <RadioGroupItem value="48k" aria-label="48 kHz" />
 * </RadioGroup>
 */
function RadioGroup({ className, ...props }: RadioGroupProps) {
  return (
    <BaseRadioGroup
      data-slot="radio-group"
      className={cn("flex flex-col gap-2.5", className)}
      {...props}
    />
  );
}

function RadioGroupItem({
  className,
  ...props
}: React.ComponentProps<typeof Radio.Root>) {
  return (
    <Radio.Root
      data-slot="radio-group-item"
      className={cn(
        "inline-flex size-4.5 shrink-0 cursor-pointer items-center justify-center rounded-full bg-well shadow-deboss-1 focus-ring transition-[box-shadow] duration-(--duration-settle) data-disabled:pointer-events-none data-disabled:opacity-50",
        className,
      )}
      {...props}
    >
      <Radio.Indicator
        data-slot="radio-group-indicator"
        className="size-2 rounded-full bg-accent shadow-emboss-1 transition-[scale,opacity] duration-(--duration-press) ease-(--ease-press) data-starting-style:scale-50 data-starting-style:opacity-0"
      />
    </Radio.Root>
  );
}

export { RadioGroup, RadioGroupItem };