Accordion 手风琴

可以折叠/展开的内容区域。

规则

  • 对复杂区域进行分组和隐藏。

  • 通常,一次只允许单个内容区域展开;特殊情况,多个内容区域可以同时展开。

代码演示

基本

Accordion

  1. import { Accordion, List } from 'antd-mobile';
  2. class AccordionExmple extends React.Component {
  3. onChange = (key) => {
  4. console.log(key);
  5. }
  6. render() {
  7. return (
  8. <div style={{ marginTop: 10, marginBottom: 10 }}>
  9. <Accordion defaultActiveKey="0" className="my-accordion" onChange={this.onChange}>
  10. <Accordion.Panel header="Title 1">
  11. <List className="my-list">
  12. <List.Item>content 1</List.Item>
  13. <List.Item>content 2</List.Item>
  14. <List.Item>content 3</List.Item>
  15. </List>
  16. </Accordion.Panel>
  17. <Accordion.Panel header="Title 2" className="pad">this is panel content2 or other</Accordion.Panel>
  18. <Accordion.Panel header="Title 3" className="pad">
  19. text text text text text text text text text text text text text text text
  20. </Accordion.Panel>
  21. </Accordion>
  22. </div>
  23. );
  24. }
  25. }
  26. ReactDOM.render(<AccordionExmple />, mountNode);
  1. .my-accordion .pad .am-accordion-content-box {
  2. padding: 10px;
  3. }

手风琴模式

Accordion

  1. import { Accordion, List } from 'antd-mobile';
  2. class AccordionExmple extends React.Component {
  3. onChange = (key) => {
  4. console.log(key);
  5. }
  6. render() {
  7. return (
  8. <div style={{ marginTop: 10, marginBottom: 10 }}>
  9. <Accordion accordion openAnimation={{}} className="my-accordion" onChange={this.onChange}>
  10. <Accordion.Panel header="Title 1">
  11. <List className="my-list">
  12. <List.Item>content 1</List.Item>
  13. <List.Item>content 2</List.Item>
  14. <List.Item>content 3</List.Item>
  15. </List>
  16. </Accordion.Panel>
  17. <Accordion.Panel header="Title 2" className="pad">this is panel content2 or other</Accordion.Panel>
  18. <Accordion.Panel header="Title 3" className="pad">
  19. text text text text text text text text text text text text text text text
  20. </Accordion.Panel>
  21. </Accordion>
  22. </div>
  23. );
  24. }
  25. }
  26. ReactDOM.render(<AccordionExmple />, mountNode);
  1. .my-accordion .pad .am-accordion-content-box {
  2. padding: 10px;
  3. }

Accordion手风琴 - 图1

API

Accordion

属性说明类型默认值
activeKey当前激活 tab 面板的 keyArray or String默认无,accordion模式下默认第一个元素
defaultActiveKey初始化选中面板的 keyString
onChange切换面板的回调(key: string): voidnoop
accordion手风琴模式Booleanfalse
openAnimation设置自定义切换动画,禁止动画可设为{}Object参考 rc-collapse/lib/openAnimationFactory.js 文件

Accordion.Panel

属性说明类型默认值
key对应 activeKeyString
header面板头内容React.Element or String
注意: 目前暂不支持嵌套使用