# 单选框组 · JGuang UI

> 从一组互斥选项中选择一项。

- 页面: https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group
- 改编自: shadcn/ui 文档 (MIT) @ bc0705384b51252af26dcc65425b216bf5eb063c
- 说明：正文保留英文原文。

> 示例 `radio-group-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## Installation


  

**Command**


  

**Manual**


```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```


### Install the following dependencies:


```bash
npm install radix-ui
```


### Copy and paste the following code into your project.


[View complete source: components/ui/radio-group.tsx](/r/jguang-ui/radix/radio-group.json)


### Update the import paths to match your project setup.


## Usage

```tsx showLineNumbers
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
```

```tsx showLineNumbers
<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`:

```text
RadioGroup
├── RadioGroupItem
└── RadioGroupItem
```

## Description

Radio group items with a description using the `Field` component.


> 示例 `radio-group-description`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## Choice Card

Use `FieldLabel` to wrap the entire `Field` for a clickable card-style selection.


> 示例 `radio-group-choice-card`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## Fieldset

Use `FieldSet` and `FieldLegend` to group radio items with a label and description.


> 示例 `radio-group-fieldset`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## Disabled

Use the `disabled` prop on `RadioGroupItem` to disable individual items.


> 示例 `radio-group-disabled`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## Invalid

Use `aria-invalid` on `RadioGroupItem` and `data-invalid` on `Field` to show validation errors.


> 示例 `radio-group-invalid`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## RTL

To enable RTL support in JGuang UI, see the [RTL configuration guide](/systems/jguang-ui/docs/rtl).


> 示例 `radio-group-rtl`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/radio-group


## API Reference

See the [Radix UI Radio Group](https://www.radix-ui.com/docs/primitives/components/radio-group#api-reference) documentation.

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
