# rc-collapse

> rc-collapse ui component for react

Latest version **4.0.0** (published 2025-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install rc-collapse
pnpm add rc-collapse
yarn add rc-collapse
bun add rc-collapse
```

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2025-01-07 |
| First published | 2015-07-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 4 |
| Unpacked size | 52.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 332 |
| Maintainers | shepherdwind, afc163, yiminghe, zombiej, lixuan, madccc |
| Keywords | react, react-component, react-rc-collapse, rc-collapse, collapse, accordion |

## Links

- npm: https://www.npmjs.com/package/rc-collapse
- Repository: https://github.com/react-component/collapse
- Homepage: http://github.com/react-component/collapse
- Issues: http://github.com/react-component/collapse/issues
- npm.io page: https://npm.io/package/rc-collapse

## Dependencies (4)

- [rc-util](https://npm.io/package/rc-util.md) ^5.27.0
- [rc-motion](https://npm.io/package/rc-motion.md) ^2.3.4
- [classnames](https://npm.io/package/classnames.md) 2.x
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.10.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.0 (latest) — 2025-01-07
- 3.9.0 — 2024-10-28
- 3.8.0 — 2024-08-23
- 3.7.3 — 2024-03-16
- 3.7.2 — 2023-11-28
- 3.7.1 — 2023-07-31
- 3.7.0 — 2023-05-23
- 3.6.0 — 2023-04-14
- 3.5.2 — 2023-02-01
- 3.5.1 — 2023-01-13
- 3.5.0 — 2023-01-12
- 3.4.2 — 2022-09-17
- 3.4.1 — 2022-09-17
- 3.4.0 — 2022-09-03
- 3.3.1 — 2022-07-01
- … 69 more at https://npm.io/package/rc-collapse/versions

## README

# rc-collapse

rc-collapse ui component for react

[![NPM version][npm-image]][npm-url] [![build status][github-actions-image]][github-actions-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/rc-collapse.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-collapse
[github-actions-image]: https://github.com/react-component/collapse/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/collapse/actions
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/collapse/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/collapse
[download-image]: https://img.shields.io/npm/dm/rc-collapse.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-collapse

## Live Demo

https://collapse-react-component.vercel.app

## Install

[![rc-collapse](https://nodei.co/npm/rc-collapse.png)](https://npmjs.org/package/rc-collapse)

## Usage

```js
var Collapse = require('rc-collapse');
var Panel = Collapse.Panel;
var React = require('react');
var ReactDOM = require('react-dom');
require('rc-collapse/assets/index.css');

var App = (
  <Collapse accordion={true}>
    <Panel header="hello" headerClass="my-header-class">
      this is panel content
    </Panel>
    <Panel header="title2">this is panel content2 or other</Panel>
  </Collapse>
);
ReactDOM.render(App, container);
```

## Features

- support ie8,ie8+,chrome,firefox,safari

## API

### Collapse props

<table class="table table-bordered table-striped">
    <thead>
    <tr>
        <th style="width: 100px;">name</th>
        <th style="width: 50px;">type</th>
        <th>default</th>
        <th>description</th>
    </tr>
    </thead>
    <tbody>
      <tr>
          <td>activeKey</td>
          <td>String|Array<String></td>
          <th>The first panel key</th>
          <td>current active Panel key</td>
      </tr>
      <tr>
        <td>className</td>
        <td>String or object</td>
        <th></th>
        <td>custom className to apply</td>
      </tr>
      <tr>
          <td>defaultActiveKey</td>
          <td>String|Array<String></td>
          <th>null</th>
          <td>default active key</td>
      </tr>
      <tr>
          <td>destroyInactivePanel</td>
          <td>Boolean</td>
          <th>false</th>
          <td>If destroy the panel which not active, default false. </td>
      </tr>
      <tr>
          <td>accordion</td>
          <td>Boolean</td>
          <th>false</th>
          <td>accordion mode, default is null, is collapse mode</td>
      </tr>
      <tr>
          <td>onChange</td>
          <td>Function(key)</td>
          <th>noop</th>
          <td>called when collapse Panel is changed</td>
      </tr>
      <tr>
          <td>expandIcon</td>
          <td>(props: PanelProps) => ReactNode</td>
          <th></th>
          <td>specific the custom expand icon.</td>
      </tr>
      <tr>
          <td>collapsible</td>
          <td>'header' | 'icon' | 'disabled'</td>
          <th>-</th>
          <td>specify whether the panel of children is collapsible or the area of collapsible.</td>
      </tr>
      <tr>
          <td>items</td>
          <td>
            <a href="./src/interface.ts#ItemType">interface.ts#ItemType</a>
          </td>
          <th>-</th>
          <td>collapse items content</td>
      </tr>
    </tbody>
</table>

If `accordion` is null or false, every panel can open. Opening another panel will not close any of the other panels. `activeKey` should be an string, if passing an array (the first item in the array will be used).

If `accordion` is true, only one panel can be open. Opening another panel will cause the previously opened panel to close. `activeKey` should be an string, if passing an array (the first item in the array will be used).

### Collapse.Panel props

> **deprecated** use `items` instead, will be removed in `v4.0.0`

<table class="table table-bordered table-striped">
    <thead>
    <tr>
        <th style="width: 100px;">name</th>
        <th style="width: 200px;">type</th>
        <th>default</th>
        <th>description</th>
    </tr>
    </thead>
    <tbody>
      <tr>
          <td>header</td>
          <td>String or node</td>
          <th></th>
          <td>header content of Panel</td>
      </tr>
      <tr>
          <td>headerClass</td>
          <td>String</td>
          <th>' '</th>
          <td>custom className to apply to header</td>
      </tr>
      <tr>
          <td>showArrow</td>
          <td>boolean</td>
          <th>true</th>
          <td>show arrow beside header</td>
      </tr>
      <tr>
        <td>className</td>
        <td>String or object</td>
        <th></th>
        <td>custom className to apply</td>
      </tr>
      <tr>
        <td>classNames</td>
        <td>{ header?: string, body?: string }</td>
        <th></th>
        <td>Semantic structure className</td>
      </tr>
      <tr>
        <td>style</td>
        <td>object</td>
        <th></th>
        <td>custom style</td>
      </tr>
      <tr>
        <td>styles</td>
        <td>{ header?: React.CSSProperties, body?: React.CSSProperties }</td>
        <th></th>
        <td>Semantic structure styles</td>
      </tr>
      <tr>
        <td>openMotion</td>
        <td>object</td>
        <th></th>
        <td>set the animation of open behavior, [more](https://github.com/react-component/motion). Different with v2, closed pane use a `rc-collapse-content-hidden` class to set `display: none` for hidden.</td>
      </tr>
      <tr>
        <td>forceRender</td>
        <td>boolean</td>
        <th>false</th>
        <td>forced render of content in panel, not lazy render after clicking on header</td>
      </tr>
      <tr>
          <td>extra</td>
          <td>String | ReactNode</td>
          <th></th>
          <td>Content to render in the right of the panel header</td>
      </tr>
      <tr>
          <td>collapsible</td>
          <td>'header' | 'icon' | 'disabled'</td>
          <th>-</th>
          <td>specify whether the panel be collapsible or the area of collapsible.</td>
      </tr>
    </tbody>
</table>

> `disabled` is removed since 3.0.0, please use `collapsible=disabled` replace it.

#### key

If `key` is not provided, the panel's index will be used instead.

#### KeyBoard Event

By default, Collapse will listen `onKeyDown`(<3.7.0 `onKeyPress`) event with `enter` key to toggle panel's active state when `collapsible` is not `disabled`. If you want to disable this behavior, you can prevent the event from bubbling like this:

```tsx | pure
const App = () => {
  const items: CollapseProps['items'] = [
    {
      label: <input onKeyDown={(e) => e.stopPropagation()} />,
      children: 'content',
    },
    {
      label: (
        <div onKeyDown={(e) => e.stopPropagation()}>
          <CustomComponent />
        </div>
      ),
      children: 'content',
    },
    {
      label: 'title 2',
      children: 'content 2',
      collapsible: 'disabled',
    },
    {
      label: 'title 3',
      children: 'content 3',
      onItemClick: console.log,
    },
  ];

  return <Collapse items={items} />;
};
```

## Development

```bash
npm install
npm start
```

## Test Case

```bash
npm test
```

## Coverage

```bash
npm test -- --coverage
```

## License

rc-collapse is released under the MIT license.

---
_Source: https://npm.io/package/rc-collapse · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
