Loading...
Loading...
> A set of checkable buttons where only one can be checked at a time, built with Radix UI.
1import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
1<RadioGroup value={value} onValueChange={setValue}>2 <div className="flex items-center space-x-2">3 <RadioGroupItem value="option1" id="r1" />4 <Label htmlFor="r1">[DEFAULT OPTION]:</Label>5 </div>6 <div className="flex items-center space-x-2">7 <RadioGroupItem value="option2" id="r2" />8 <Label htmlFor="r2">[ALTERNATIVE OPTION]:</Label>9 </div>10</RadioGroup>
1<RadioGroup2 value={value}3 onValueChange={setValue}4 className="flex flex-row space-x-4"5>6 <div className="flex items-center space-x-2">7 <RadioGroupItem value="sm" id="h1" />8 <Label htmlFor="h1">[SMALL]:</Label>9 </div>10 {/* More items... */}11</RadioGroup>
Pay with credit or debit card
Direct bank account transfer
Pay with Bitcoin or Ethereum
1<RadioGroup value={value} onValueChange={setValue}>2 <div className="flex items-start space-x-2">3 <RadioGroupItem value="card" id="d1" className="mt-1" />4 <div className="space-y-1">5 <Label htmlFor="d1">[CARD PAYMENT]:</Label>6 <p className="text-sm text-muted-foreground">7 Pay with credit or debit card8 </p>9 </div>10 </div>11 {/* More items... */}12</RadioGroup>
1<RadioGroup defaultValue="enabled">2 <div className="flex items-center space-x-2">3 <RadioGroupItem value="enabled" id="e1" />4 <Label htmlFor="e1">[ENABLED OPTION]:</Label>5 </div>6 <div className="flex items-center space-x-2">7 <RadioGroupItem value="disabled" id="e2" disabled />8 <Label htmlFor="e2">[DISABLED OPTION]:</Label>9 </div>10</RadioGroup>
1<div className="space-y-2">2 <div className="font-mono text-xs text-muted-foreground">3 [SELECT OPTION]:4 </div>5 <RadioGroup defaultValue="option1">6 <div className="flex items-center space-x-2">7 <RadioGroupItem value="option1" id="t1" />8 <Label htmlFor="t1" className="font-mono text-xs">9 > INITIALIZE PROJECT10 </Label>11 </div>12 {/* More items... */}13 </RadioGroup>14</div>
| Prop | Type | Default | Description |
|---|---|---|---|
| value | string | undefined | The controlled value of the selected radio item |
| defaultValue | string | undefined | The default value for uncontrolled usage |
| onValueChange | (value: string) => void | undefined | Callback fired when the selected value changes |
| disabled | boolean | false | Disable all radio items in the group |
| required | boolean | false | Mark the radio group as required |
| name | string | undefined | Name attribute for form submission |
| className | string | undefined | Additional CSS classes for the container |
✓ Use Radio Group when:
✗ Don't use when:
Best Practices: