# 折叠面板 · JGuang UI

> 显示或隐藏一段独立的扩展内容。

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

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


## 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/collapsible.tsx](/r/jguang-ui/radix/collapsible.json)


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


## Usage

```tsx showLineNumbers
import {
  Collapsible,
  CollapsibleContent,
  CollapsibleTrigger,
} from "@/components/ui/collapsible"
```

```tsx showLineNumbers
<Collapsible>
  <CollapsibleTrigger>Can I use this in my project?</CollapsibleTrigger>
  <CollapsibleContent>
    Yes. Free to use for personal and commercial projects. No attribution
    required.
  </CollapsibleContent>
</Collapsible>
```

## Composition

Use the following composition to build a `Collapsible`:

```text
Collapsible
├── CollapsibleTrigger
└── CollapsibleContent
```

## Controlled State

Use the `open` and `onOpenChange` props to control the state.

```tsx showLineNumbers
import * as React from "react"

export function Example() {
  const [open, setOpen] = React.useState(false)

  return (
    <Collapsible open={open} onOpenChange={setOpen}>
      <CollapsibleTrigger>Toggle</CollapsibleTrigger>
      <CollapsibleContent>Content</CollapsibleContent>
    </Collapsible>
  )
}
```

## Basic


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


## Settings Panel

Use a trigger button to reveal additional settings.


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


## File Tree

Use nested collapsibles to build a file tree.


> 示例 `collapsible-file-tree`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/radix/collapsible


## RTL

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


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


## API Reference

See the [Radix UI](https://www.radix-ui.com/docs/primitives/components/collapsible#api-reference) documentation for more information.

---

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