Basic UI
  • Docs
  • Compressor
  • Parser
Getting Started
  • Introduction
  • Themenew
Components
  • Button
  • Button Group
  • Badge
  • Radio Group
  • Checkbox
  • Avatar
  • Label
  • File Dropzone
  1. Docs/
  2. Components/
  3. Radio Group

Radio Group

Previous pageNext page

A set of radio inputs built on Radix primitives. Only one option can be selected at a time.

Loading...

Installation

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

Usage

import {
  RadioGroup,
  RadioGroupItem,
























Previous
Badge
Next
Checkbox

On This Page

InstallationUsageExamplesSizesDesign SystemSizePropsRadioGroupRadioGroupItemWrapperRadioGroupItem
radio-group-default
RadioGroupItemWrapper,
} from '@/registry/basic-ui/radio-group';
export default function RadioGroupDefault() {
return (
<RadioGroup defaultValue="comfortable">
<RadioGroupItemWrapper htmlFor="r1">
<RadioGroupItem value="default" id="r1" />
<span>Default</span>
</RadioGroupItemWrapper>
<RadioGroupItemWrapper htmlFor="r2">
<RadioGroupItem value="comfortable" id="r2" />
<span>Comfortable</span>
</RadioGroupItemWrapper>
<RadioGroupItemWrapper htmlFor="r3">
<RadioGroupItem value="checked" id="r3" checked disabled />
<span>Checked and Disabled</span>
</RadioGroupItemWrapper>
<RadioGroupItemWrapper htmlFor="r4">
<RadioGroupItem value="disabled" id="r4" disabled />
<span>Disabled and Not Checked</span>
</RadioGroupItemWrapper>
</RadioGroup>
);
}

Examples

Sizes

Displays the available size tokens for the radio item along with shared wrappers.

Loading...

Design System

Size

SizeHeightWidthRadius
s--checkbox-radio-height-s--checkbox-radio-width-s--checkbox-radio-radius-s
r--checkbox-radio-height-r--checkbox-radio-width-r--checkbox-radio-radius-r
m--checkbox-radio-height-m--checkbox-radio-width-m--checkbox-radio-radius-m

Props

RadioGroup

PropTypeDefaultRequiredDescription
sizes / r / mrNoThe size of the radio group
defaultValuestringundefinedNoThe default value of the radio group
onValueChange(value: string) => voidundefinedNoThe function to call when the value changes
disabledbooleanfalseNoWhether the radio group is disabled
classNamestringundefinedNoThe class name of the radio group

RadioGroupItemWrapper

PropTypeDefaultRequiredDescription
htmlForstringundefinedYesThe HTML for attribute of the radio group item wrapper
childrenReactNodeundefinedYesThe children of the radio group item wrapper
classNamestringundefinedNoThe class name of the radio group item wrapper

RadioGroupItem

PropTypeDefaultRequiredDescription
valuestringundefinedYesThe value of the radio group item
idstringundefinedYesThe id of the radio group item
classNamestringundefinedNoThe class name of the radio group item
radio-group-size
Compact (s)
Regular (r)
Comfortable (m)
import {
  RadioGroup,
  RadioGroupItem,
  RadioGroupItemWrapper,
} from '@/registry/basic-ui/radio-group';

export function RadioGroupDefault() {
  return (
    <RadioGroup defaultValue="comfortable">
      <RadioGroupItemWrapper htmlFor="r1">
        <RadioGroupItem value="default" id="r1" />
        <span>Default</span>
      </RadioGroupItemWrapper>
      <RadioGroupItemWrapper htmlFor="r2">
        <RadioGroupItem value="comfortable" id="r2" />
        <span>Comfortable</span>
      </RadioGroupItemWrapper>
      <RadioGroupItemWrapper htmlFor="r3">
        <RadioGroupItem value="checked" id="r3" checked disabled />
        <span>Checked and Disabled</span>
      </RadioGroupItemWrapper>
      <RadioGroupItemWrapper htmlFor="r4">
        <RadioGroupItem value="disabled" id="r4" disabled />
        <span>Disabled and Not Checked</span>
      </RadioGroupItemWrapper>
    </RadioGroup>
  );
}
'use client';

import {
  RadioGroup,
  RadioGroupItem,
  RadioGroupItemWrapper,
} from '@/registry/basic-ui/radio-group';

const sizeConfigs: Array<{
  id: string;
  label: string;
  size: 's' | 'r' | 'm';
}> = [
  { id: 'radio-size-s', label: 'Compact (s)', size: 's' },
  { id: 'radio-size-r', label: 'Regular (r)', size: 'r' },
  { id: 'radio-size-m', label: 'Comfortable (m)', size: 'm' },
];

export function RadioGroupSize() {
  return (
    <div className="flex flex-col gap-(--gap-6)">
      {sizeConfigs.map(({ id, label, size }) => (
        <fieldset key={id} className="space-y-3">
          <legend className="text-sm font-semibold text-(--grey-text-alpha-1-default)">
            {label}
          </legend>
          <RadioGroup
            size={size}
            defaultValue={`${id}-email`}
            className="gap-(--gap-2)"
          >
            <RadioGroupItemWrapper htmlFor={`${id}-email`}>
              <RadioGroupItem id={`${id}-email`} value={`${id}-email`} />
              <span>Email alerts</span>
            </RadioGroupItemWrapper>
            <RadioGroupItemWrapper htmlFor={`${id}-sms`}>
              <RadioGroupItem id={`${id}-sms`} value={`${id}-sms`} />
              <span>SMS alerts</span>
            </RadioGroupItemWrapper>
          </RadioGroup>
        </fieldset>
      ))}
    </div>
  );
}