Docs
单选组

单选组

一组可检查的按钮(称为无线按钮),其中任何时候只能选中一个按钮。

安装

npx shadcn-ui@latest add radio-group

使用

import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
<RadioGroup defaultValue="option-one">
  <div className="flex items-center space-x-2">
    <RadioGroupItem value="option-one" id="option-one" />
    <Label htmlFor="option-one">选项一</Label>
  </div>
  <div className="flex items-center space-x-2">
    <RadioGroupItem value="option-two" id="option-two" />
    <Label htmlFor="option-two">选项二</Label>
  </div>
</RadioGroup>

示例

表单