eo-n/ui
UIComponentsRadio Group

Radio Group

Lets the user select exactly one option from a set of radio buttons.

Installation

CLI

npx shadcn@latest add "https://eo-n.vercel.app/r/radio-group"

Manual

Copy and paste the following code into your project.

"use client";
 
import * as React from "react";
import { Radio as RadioPrimitive } from "@base-ui-components/react/radio";
import { RadioGroup as RadioGroupPrimitive } from "@base-ui-components/react/radio-group";
 
import { cn } from "@/lib/utils";
 
function RadioGroup({
  className,
  ...props
}: React.ComponentProps<typeof RadioGroupPrimitive>) {
  return (
    <RadioGroupPrimitive
      data-slot="radio-group"
      className={cn("flex flex-col gap-2.5", className)}
      {...props}
    />
  );
}
 
function RadioGroupItem({
  className,
  ...props
}: React.ComponentProps<typeof RadioPrimitive.Root>) {
  return (
    <RadioPrimitive.Root
      data-slot="radio-group-item"
      className={cn(
        "peer data-[checked]:bg-primary data-[unchecked]:border-primary flex size-4 shrink-0 items-center justify-center rounded-full outline-none disabled:cursor-not-allowed disabled:opacity-50 data-[unchecked]:border data-[unchecked]:bg-transparent",
        className
      )}
      {...props}
    >
      <RadioPrimitive.Indicator className="before:bg-background flex before:size-2 before:rounded-full data-[unchecked]:hidden" />
    </RadioPrimitive.Root>
  );
}
 
export { RadioGroup, RadioGroupItem };
Update the import paths to match your project setup.

Usage

Import all parts and piece them together.

import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
<RadioGroup>
  <div className="flex items-center space-x-2">
    <RadioGroupItem value="right" id="right" />
    <Label htmlFor="right">Right</Label>
  </div>
  <div className="flex items-center space-x-2">
    <RadioGroupItem value="left" id="left" />
    <Label htmlFor="left">Left</Label>
  </div>
</RadioGroup>

Examples

Disabled Item

On this page