logoAnt Design

⌘ K
  • 设计
  • 研发
  • 组件
  • 博客
  • 资源
  • 国内镜像
5.20.6
  • 组件总览
  • 通用
    • Button
      按钮
    • FloatButton
      悬浮按钮
      5.0.0
    • Icon
      图标
    • Typography
      排版
  • 布局
    • Divider
      分割线
    • Flex
      弹性布局
      5.10.0
    • Grid
      栅格
    • Layout
      布局
    • Space
      间距
  • 导航
    • Anchor
      锚点
    • Breadcrumb
      面包屑
    • Dropdown
      下拉菜单
    • Menu
      导航菜单
    • Pagination
      分页
    • Steps
      步骤条
  • 数据录入
    • AutoComplete
      自动完成
    • Cascader
      级联选择
    • Checkbox
      多选框
    • ColorPicker
      颜色选择器
      5.5.0
    • DatePicker
      日期选择框
    • Form
      表单
    • Input
      输入框
    • InputNumber
      数字输入框
    • Mentions
      提及
    • Radio
      单选框
    • Rate
      评分
    • Select
      选择器
    • Slider
      滑动输入条
    • Switch
      开关
    • TimePicker
      时间选择框
    • Transfer
      穿梭框
    • TreeSelect
      树选择
    • Upload
      上传
  • 数据展示
    • Avatar
      头像
    • Badge
      徽标数
    • Calendar
      日历
    • Card
      卡片
    • Carousel
      走马灯
    • Collapse
      折叠面板
    • Descriptions
      描述列表
    • Empty
      空状态
    • Image
      图片
    • List
      列表
    • Popover
      气泡卡片
    • QRCode
      二维码
      5.1.0
    • Segmented
      分段控制器
    • Statistic
      统计数值
    • Table
      表格
    • Tabs
      标签页
    • Tag
      标签
    • Timeline
      时间轴
    • Tooltip
      文字提示
    • Tour
      漫游式引导
      5.0.0
    • Tree
      树形控件
  • 反馈
    • Alert
      警告提示
    • Drawer
      抽屉
    • Message
      全局提示
    • Modal
      对话框
    • Notification
      通知提醒框
    • Popconfirm
      气泡确认框
    • Progress
      进度条
    • Result
      结果
    • Skeleton
      骨架屏
    • Spin
      加载中
    • Watermark
      水印
      5.1.0
  • 其他
    • Affix
      固钉
    • App
      包裹组件
      5.1.0
    • ConfigProvider
      全局化配置
    • Util
      工具类
      5.13.0

Collapse
折叠面板

可以折叠/展开的内容区域。
使用import{ Collapse }from"antd";
源码components/collapse
文档编辑此页

相关资源

Ant Design Charts
Ant Design Pro
Ant Design Pro Components
Ant Design Mobile
Ant Design Mini
Ant Design Landing-首页模板集
Scaffolds-脚手架市场
Umi-React 应用开发框架
dumi-组件/文档研发工具
qiankun-微前端框架
ahooks-React Hooks 库
Ant Motion-设计动效
国内镜像站点 🇨🇳

社区

Awesome Ant Design
Medium
Twitter
yuque logoAnt Design 语雀专栏
Ant Design 知乎专栏
体验科技专栏
seeconf logoSEE Conf-蚂蚁体验科技大会
加入我们

帮助

GitHub
更新日志
常见问题
报告 Bug
议题
讨论区
StackOverflow
SegmentFault

Ant XTech logo更多产品

yuque logo语雀-构建你的数字花园
AntV logoAntV-数据可视化解决方案
Egg logoEgg-企业级 Node.js 框架
Kitchen logoKitchen-Sketch 工具集
Galacean logoGalacean-互动图形解决方案
xtech logo蚂蚁体验科技
主题编辑器
Made with ❤ by
蚂蚁集团和 Ant Design 开源社区
loading

何时使用

  • 对复杂区域进行分组和隐藏,保持页面的整洁。
  • 手风琴 是一种特殊的折叠面板,只允许单个内容区域展开。
// >= 5.6.0 可用,推荐的写法 ✅
const text = `
A dog is a type of domesticated animal.
Known for its loyalty and faithfulness,
it can be found as a welcome guest in many households across the world.
`;
const items: CollapseProps['items'] = [
{
key: '1',
label: 'This is panel header 1',
children: <p>{text}</p>,
},
{
key: '2',
label: 'This is panel header 2',
children: <p>{text}</p>,
},
{
key: '3',
label: 'This is panel header 3',
children: <p>{text}</p>,
},
];
<Collapse items={items} defaultActiveKey={['1']} />;
// <5.6.0 可用,>=5.6.0 时不推荐 🙅🏻‍♀️
<Collapse defaultActiveKey={['1']} onChange={onChange}>
<Panel header="This is panel header 1" key="1">
<p>{text}</p>
</Panel>
<Panel header="This is panel header 2" key="2">
<p>{text}</p>
</Panel>
<Panel header="This is panel header 3" key="3">
<p>{text}</p>
</Panel>
</Collapse>;

代码演示

This is panel header 1

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This is panel header 2
This is panel header 3
折叠面板

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

codepen icon
External Link Icon
expand codeexpand code
Default Size
This is default size panel header
Small Size
This is small size panel header
Large Size
This is large size panel header
面板尺寸

折叠面板有大、中、小三种尺寸。

通过设置 size 为 large small 分别把折叠面板设为大、小尺寸。若不设置 size,则尺寸默认为中。

codepen icon
External Link Icon
expand codeexpand code
This is panel header 1
This is panel header 2
This is panel header 3
手风琴

手风琴模式,始终只有一个面板处在激活状态。

codepen icon
External Link Icon
expand codeexpand code
This is panel header 1
This is panel header 2
This is panel header 3
面板嵌套

嵌套折叠面板。

codepen icon
External Link Icon
expand codeexpand code
This is panel header 1

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This is panel header 2
This is panel header 3
简洁风格

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

codepen icon
External Link Icon
expand codeexpand code
This is panel header 1

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This is panel header 2
This is panel header 3
自定义面板

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

codepen icon
External Link Icon
expand codeexpand code
This is panel header with arrow icon

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This is panel header with no arrow icon
隐藏箭头

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

codepen icon
External Link Icon
expand codeexpand code
This is panel header 1
A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.
This is panel header 2
This is panel header 3

Expand Icon Position:
start
额外节点

自定义渲染每个面板右上角的内容。

codepen icon
External Link Icon
expand codeexpand code
This is panel header 1

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This is panel header 2
This is panel header 3
幽灵折叠面板

将折叠面板的背景变成透明。

codepen icon
External Link Icon
expand codeexpand code
This panel can only be collapsed by clicking text

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This panel can only be collapsed by clicking icon

A dog is a type of domesticated animal. Known for its loyalty and faithfulness, it can be found as a welcome guest in many households across the world.

This panel can't be collapsed
可折叠触发区域

通过 collapsible 属性,可以设置面板的可折叠触发区域。

codepen icon
External Link Icon
expand codeexpand code

API

通用属性参考:通用属性

Collapse

参数说明类型默认值版本
accordion手风琴模式booleanfalse
activeKey当前激活 tab 面板的 keystring[] | string
number[] | number
手风琴模式下默认第一个元素
bordered带边框风格的折叠面板booleantrue
collapsible所有子面板是否可折叠或指定可折叠触发区域header | icon | disabled-4.9.0
defaultActiveKey初始化选中面板的 keystring[] | string
number[] | number
-
destroyInactivePanel销毁折叠隐藏的面板booleanfalse
expandIcon自定义切换图标(panelProps) => ReactNode-
expandIconPosition设置图标位置start | end-4.21.0
ghost使折叠面板透明且无边框booleanfalse4.4.0
size设置折叠面板大小large | middle | smallmiddle5.2.0
onChange切换面板的回调function-
items折叠项目内容ItemType-5.6.0

Collapse.Panel

已废弃

版本 >= 5.6.0 时请使用 items 方式配置面板。

参数说明类型默认值版本
collapsible是否可折叠或指定可折叠触发区域header | icon | disabled-4.9.0 (icon: 4.24.0)
extra自定义渲染每个面板右上角的内容ReactNode-
forceRender被隐藏时是否渲染 DOM 结构booleanfalse
header面板头内容ReactNode-
key对应 activeKeystring | number-
showArrow是否展示当前面板上的箭头(为 false 时,collapsible 不能置为 icon)booleantrue

主题变量(Design Token)

组件 Token如何定制?

Token 名称描述类型默认值
contentBg折叠面板内容背景string#ffffff
contentPadding折叠面板内容内边距undefined | Padding<string | number>16px 16px
headerBg折叠面板头部背景stringrgba(0, 0, 0, 0.02)
headerPadding折叠面板头部内边距undefined | Padding<string | number>12px 16px

全局 Token如何定制?