单选框组
从一组互斥选项中选择一项。
安装
Command
Manual
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
安装以下依赖:
npm install @base-ui/react
将以下代码复制到你的项目中。
View complete source: components/ui/radio-group.tsx
根据项目配置更新导入路径。
用法
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
<RadioGroup defaultValue="option-one">
<div className="flex items-center gap-3">
<RadioGroupItem value="option-one" id="option-one" />
<Label htmlFor="option-one">Option One</Label>
</div>
<div className="flex items-center gap-3">
<RadioGroupItem value="option-two" id="option-two" />
<Label htmlFor="option-two">Option Two</Label>
</div>
</RadioGroup>
Composition
Use the following composition to build a RadioGroup:
RadioGroup
├── RadioGroupItem
└── RadioGroupItem
Description
Radio group items with a description using the Field component.
Choice Card
Use FieldLabel to wrap the entire Field for a clickable card-style selection.
Fieldset
Use FieldSet and FieldLegend to group radio items with a label and description.
Disabled
Use the disabled prop on RadioGroup to disable all items.
Invalid
Use aria-invalid on RadioGroupItem and data-invalid on Field to show validation errors.
从右到左布局
To enable RTL support in JGuang UI, see the RTL configuration guide.
API 参考
See the Base UI Radio Group documentation.
来源: components/base/radio-group.mdx
JGuang UI 技术文档。