# 切换按钮组 · JGuang UI

> 从一组切换按钮中选择单项或多项。

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

> 示例 `toggle-group-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/toggle-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/toggle-group.tsx](/r/jguang-ui/radix/toggle-group.json)


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


## Usage

```tsx
import { ToggleGroup, ToggleGroupItem } from "@/components/ui/toggle-group"
```

```tsx
<ToggleGroup type="single">
  <ToggleGroupItem value="a">A</ToggleGroupItem>
  <ToggleGroupItem value="b">B</ToggleGroupItem>
  <ToggleGroupItem value="c">C</ToggleGroupItem>
</ToggleGroup>
```

## Composition

Use the following composition to build a `ToggleGroup`:

```text
ToggleGroup
├── ToggleGroupItem
└── ToggleGroupItem
```

## Outline

Use `variant="outline"` for an outline style.


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


## Size

Use the `size` prop to change the size of the toggle group.


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


## Spacing

Use `spacing` to add spacing between toggle group items.


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


## Vertical

Use `orientation="vertical"` for vertical toggle groups.


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


## Disabled


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


## Custom

A custom toggle group example.


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


## RTL

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


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


## API Reference

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

## Changelog

### 2026-05-17 Default Spacing

Changed the default `spacing` from `0` to `2` so toggle groups render with space between items by default. Use `spacing={0}` for connected items.

---

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