Skip to content
Corsair UI
Browse the docs

ComponentsNo. 43 of 109

Radio Group

A set of options where exactly one can be selected.

Installation

pnpm dlx shadcn@latest add @corsair-ui/radio-group

No setup needed: the CLI finds @corsair-ui in the shadcn registry directory. The files land in your project as source: edit them like your own code. More in Installation.

Also adds
utils
npm
@radix-ui/react-radio-groupclsxlucide-reacttailwind-merge

Examples

Default

Horizontal, with a disabled option

API

Built on Radix Radio Group; every prop it takes is passed through.

Accessibility

  • Arrow keys move between options; the group takes a single tab stop.
  • Name the group with aria-label or a FieldSet and FieldLegend.

Compatibility

Tailwind CSS
3.4 and 4, both checked in CI
React
19
Rendering
Client component ("use client")

Source

1 file, installed as source you own
radio-group.tsxView on GitHub
"use client";

import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
import { CircleIcon } from "lucide-react";
import type { ComponentProps } from "react";

import { cn } from "@/registry/default/lib/utils";

/** Give the group an accessible name: an `aria-label`, or wrap it in a FieldSet with a FieldLegend. */
function RadioGroup({ className, ...props }: ComponentProps<typeof RadioGroupPrimitive.Root>) {
  return (
    <RadioGroupPrimitive.Root
      data-slot="radio-group"
      className={cn("grid gap-3", className)}
      {...props}
    />
  );
}

function RadioGroupItem({ className, ...props }: ComponentProps<typeof RadioGroupPrimitive.Item>) {
  return (
    <RadioGroupPrimitive.Item
      data-slot="radio-group-item"
      className={cn(
        "peer border-input bg-field text-primary aspect-square size-4 shrink-0 cursor-pointer rounded-full border",
        "transition-[color,border-color,box-shadow] outline-none motion-reduce:transition-none",
        "data-[state=checked]:border-primary",
        "focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
        "aria-[invalid=true]:border-destructive aria-[invalid=true]:ring-destructive/20",
        "disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      {...props}
    >
      {/* The dot grows in when picked and shrinks out when another option is. */}
      <RadioGroupPrimitive.Indicator
        data-slot="radio-group-indicator"
        className={cn(
          "flex size-full items-center justify-center",
          "zoom-in-0 fade-in-0 zoom-out-0 fade-out-0 ease-out",
          "motion-safe:data-[state=checked]:animate-in motion-safe:data-[state=unchecked]:animate-out"
        )}
      >
        <CircleIcon className="fill-primary stroke-primary size-2" />
      </RadioGroupPrimitive.Indicator>
    </RadioGroupPrimitive.Item>
  );
}

export { RadioGroup, RadioGroupItem };