Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rc-collapse

react-component6.4mMIT4.0.0TypeScript support: included

rc-collapse ui component for react

react, react-component, react-rc-collapse, rc-collapse, collapse, accordion

readme

rc-collapse

rc-collapse ui component for react

NPM version build status Test coverage npm download

Live Demo

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

Install

rc-collapse

Usage

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

name type default description
activeKey String|Array<String> The first panel key current active Panel key
className String or object custom className to apply
defaultActiveKey String|Array<String> null default active key
destroyInactivePanel Boolean false If destroy the panel which not active, default false.
accordion Boolean false accordion mode, default is null, is collapse mode
onChange Function(key) noop called when collapse Panel is changed
expandIcon (props: PanelProps) => ReactNode specific the custom expand icon.
collapsible 'header' | 'icon' | 'disabled' - specify whether the panel of children is collapsible or the area of collapsible.
items interface.ts#ItemType - collapse items content

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

name type default description
header String or node header content of Panel
headerClass String ' ' custom className to apply to header
showArrow boolean true show arrow beside header
className String or object custom className to apply
classNames { header?: string, body?: string } Semantic structure className
style object custom style
styles { header?: React.CSSProperties, body?: React.CSSProperties } Semantic structure styles
openMotion object 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.
forceRender boolean false forced render of content in panel, not lazy render after clicking on header
extra String | ReactNode Content to render in the right of the panel header
collapsible 'header' | 'icon' | 'disabled' - specify whether the panel be collapsible or the area of collapsible.

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 /> ), 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

npm test

Coverage

npm test -- --coverage

License

rc-collapse is released under the MIT license.

changelog

History


2.0.0 2020-05-08

  • Remove react-lifecycles-compat and prop-types.
  • Upgrade rc-animate to 3.x.
  • Use @ant-design/css-animation.

1.11.0

  • Add extra.

1.10.0 2018-08-13

  • Add expandIcon.

1.9.1 2018-05-10

  • Fix invalid aria-expanded prop in preact

1.9.0 2018-04-02

  • Add keyboard support #84

1.8.0 2018-01-30

  • Add prop forceRender to Panel #82

1.7.6 2017-06-06

  • Add prop id for Panel #69

1.7.4 2017-05-16

  • Add prop disabled !71
  • Add es module export !70

1.7.2 2017-04-25

  • Allow user to add custom header classe !66

1.7.1 2017-04-19

  • Add prop destroyInactivePanel !61

1.7.0

  • Change createClass to React.Component !58

1.6.12

  • Fix style support for Panel

1.6.11

  • Add 'showArrow' prop to Panel to toggle arrow visibility !48

1.6.10

  • Child item support null !45

1.6.6

  • add className props to Panel

1.6.5

  • fix missing rc-collapse-item-active classname on active panel header

1.6.0

  • lazy render/controllable

1.5.0

  • use css animation instead of velocity.js

1.4.0

  • only support react 0.14+

1.2.0 2015-07-10

  • 'chore' Change name to Collapse
  • 'feat' Support Collapse and Accordion

1.1.0 2015-07-09

  • test Add test
  • refactor add Panel Api