Docs
Radio Group Form

Radio Group Form

A set of checkable buttons—known as radio buttons—where no more than one of the buttons can be checked at a time.

Installation

Install the following dependencies:

npm install @radix-ui/react-radio-group

Copy and paste the following code into your project.

"use client"
 
import * as React from "react"
import * as RadioGroupPrimitive from "@radix-ui/react-radio-group"
import { Square } from "lucide-react"
 
import { cn } from "@/lib/utils"
 
const RadioGroup = React.forwardRef<
  React.ElementRef<typeof RadioGroupPrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
>(({ className, ...props }, ref) => {
  return (
    <RadioGroupPrimitive.Root
      className={cn("grid gap-2", className)}
      {...props}
      ref={ref}
    />
  )
})
RadioGroup.displayName = RadioGroupPrimitive.Root.displayName
 
const RadioGroupItem = React.forwardRef<
  React.ElementRef<typeof RadioGroupPrimitive.Item>,
  React.ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
>(({ className, ...props }, ref) => {
  return (
    <RadioGroupPrimitive.Item
      ref={ref}
      className={cn(
        "aspect-square size-5 rounded-sm text-primary focus:outline-none disabled:cursor-not-allowed disabled:opacity-50 border-2 border-black shadow-[4px_4px_0_0_#000] transition-all hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-none dark:hover:shadow-none dark:border-white dark:bg-zinc-900 dark:shadow-[4px_4px_0_0_#fff]",
        className
      )}
      {...props}
    >
      <RadioGroupPrimitive.Indicator className="flex items-center justify-center">
        <Square className="size-3 fill-current text-current" />
      </RadioGroupPrimitive.Indicator>
    </RadioGroupPrimitive.Item>
  )
})
RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName
 
export { RadioGroup, RadioGroupItem }

Copy and paste the radio-group code into your project.