Radio Group

A set of mutually exclusive radio buttons. Built on Base UI's radio primitive.

Last updated August 7, 2026

CreditsUnchangedPublished

Copied from shadcn/ui.

Overview

import { Label } from "@/components/ui/label"
import {
  RadioGroup,
  RadioGroupItem,
} from "@/components/ui/radio-group"
 
const plans = [
  { value: "default", label: "Default" },
  { value: "comfortable", label: "Comfortable" },
  { value: "compact", label: "Compact" },
]
 
export function RadioGroupDemoExample() {
  return (
    <RadioGroup defaultValue="comfortable">
      {plans.map((plan) => (
        <div key={plan.value} className="flex items-center gap-2">
          <RadioGroupItem value={plan.value} id={`radio-demo-${plan.value}`} />
          <Label htmlFor={`radio-demo-${plan.value}`}>{plan.label}</Label>
        </div>
      ))}
    </RadioGroup>
  )
}

Installation

$ npx shadcn@latest add https://ui.persian-labs.ir/r/radio-group.json

Usage

import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
 
export function Example() {
  return (
    <RadioGroup defaultValue="comfortable">
      <RadioGroupItem value="default" />
      <RadioGroupItem value="comfortable" />
      <RadioGroupItem value="compact" />
    </RadioGroup>
  )
}

Disabled

import { Label } from "@/components/ui/label"
import {
  RadioGroup,
  RadioGroupItem,
} from "@/components/ui/radio-group"
 
export function RadioGroupDisabledExample() {
  return (
    <RadioGroup defaultValue="default">
      <div className="flex items-center gap-2">
        <RadioGroupItem value="default" id="radio-disabled-default" />
        <Label htmlFor="radio-disabled-default">Default</Label>
      </div>
      <div className="flex items-center gap-2">
        <RadioGroupItem value="compact" id="radio-disabled-compact" disabled />
        <Label htmlFor="radio-disabled-compact">Compact</Label>
      </div>
    </RadioGroup>
  )
}

RTL

import { Label } from "@/components/ui/label"
import {
  RadioGroup,
  RadioGroupItem,
} from "@/components/ui/radio-group"
 
const plans = [
  { value: "default", label: "پیش‌فرض" },
  { value: "comfortable", label: "راحت" },
  { value: "compact", label: "فشرده" },
]
 
export function RadioGroupRtlExample() {
  return (
    <RadioGroup defaultValue="comfortable">
      {plans.map((plan) => (
        <div key={plan.value} className="flex items-center gap-2">
          <RadioGroupItem value={plan.value} id={`radio-rtl-${plan.value}`} />
          <Label htmlFor={`radio-rtl-${plan.value}`}>{plan.label}</Label>
        </div>
      ))}
    </RadioGroup>
  )
}

API Reference

RadioGroup

PropTypeDefaultDescription
valuestringundefinedThe selected value. Use when controlled.
defaultValuestringundefinedThe initially selected value when uncontrolled.
onValueChange(value, details) => voidCalled when the selected value changes.
disabledbooleanfalsePrevents interaction with the whole group.

RadioGroupItem

PropTypeDefaultDescription
valuestringrequiredThe value associated with this radio item.
disabledbooleanfalsePrevents selection of this item.