Collapse折叠面板

    • 对复杂区域进行分组和隐藏,保持页面的整洁。

    • 是一种特殊的折叠面板,只允许单个内容区域展开。

    折叠面板

    可以同时展开多个面板,这个例子默认展开了第一个。

    Collapse折叠面板 - 图2

    1. import { Collapse } from 'antd';
    2. const { Panel } = Collapse;
    3. const text = `
    4. A dog is a type of domesticated animal.
    5. Known for its loyalty and faithfulness,
    6. it can be found as a welcome guest in many households across the world.
    7. `;
    8. ReactDOM.render(
    9. <Collapse accordion>
    10. <Panel header="This is panel header 1" key="1">
    11. <p>{text}</p>
    12. </Panel>
    13. <Panel header="This is panel header 2" key="2">
    14. <p>{text}</p>
    15. </Panel>
    16. <Panel header="This is panel header 3" key="3">
    17. </Panel>
    18. </Collapse>,
    19. mountNode,
    20. );

    面板嵌套

    嵌套折叠面板。

    Collapse折叠面板 - 图4

    一套没有边框的简洁样式。

    1. import { Collapse } from 'antd';
    2. const { Panel } = Collapse;
    3. const text = (
    4. <p style={{ paddingLeft: 24 }}>
    5. A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found
    6. as a welcome guest in many households across the world.
    7. </p>
    8. );
    9. ReactDOM.render(
    10. <Collapse bordered={false} defaultActiveKey={['1']}>
    11. <Panel header="This is panel header 1" key="1">
    12. {text}
    13. </Panel>
    14. <Panel header="This is panel header 2" key="2">
    15. {text}
    16. </Panel>
    17. <Panel header="This is panel header 3" key="3">
    18. {text}
    19. </Panel>
    20. mountNode,
    21. );

    自定义各个面板的背景色、圆角、边距和图标。

    Collapse折叠面板 - 图6

    隐藏箭头

    你可以通过 showArrow={false} 隐藏 CollapsePanel 组件的箭头图标。

    1. import { Collapse } from 'antd';
    2. const { Panel } = Collapse;
    3. console.log(key);
    4. }
    5. const text = `
    6. A dog is a type of domesticated animal.
    7. Known for its loyalty and faithfulness,
    8. it can be found as a welcome guest in many households across the world.
    9. `;
    10. ReactDOM.render(
    11. <Collapse defaultActiveKey={['1']} onChange={callback}>
    12. <Panel header="This is panel header with arrow icon" key="1">
    13. <p>{text}</p>
    14. </Panel>
    15. <Panel showArrow={false} header="This is panel header with no arrow icon" key="2">
    16. <p>{text}</p>
    17. </Panel>
    18. </Collapse>,
    19. mountNode,

    可以同时展开多个面板,这个例子默认展开了第一个。

    Collapse.Panel

    参数说明类型默认值
    disabled禁用后的面板展开与否将无法通过用户交互改变booleanfalse
    forceRender被隐藏时是否渲染 DOM 结构booleanfalse
    header面板头内容string|ReactNode
    key对应 activeKeystring
    showArrow是否展示当前面板上的箭头booleantrue
    extra自定义渲染每个面板右上角的内容ReactNode-