98.0k

单选框组 Radio Group

PreviousNext

一组可选按钮——称为单选按钮——一次最多只能选中其中一个按钮。

安装

pnpm dlx shadcn@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>