Skip to content

Accordion 手风琴

基本用法

对复杂区域进行分组和隐藏,保持页面的整洁。
手风琴是一种特殊的折叠面板,用于显示和隐藏内容,只允许单个内容区域展开。

const items = [
{
header: "This is panel header 1",
defaultActive: true,
content: "This is panel content 1",
},
{
header: "This is panel header 2",
content: "This is panel content 2",
},
{
header: "This is panel header 3",
content: "This is panel content 3",
},
];
<Accordion name="demo" items={items} />
aaaThis is panel header 1
This is panel content 1
This is panel header 2
This is panel content 2
This is panel header 3
This is panel content 3

代码演示

使用图标

你可以通过 showIcon 展示 Panel 组件的箭头图标。
showIcon=true 时,默认值使用 collapse-arrow。 其他 icon 目前有 collapse-plus

const items = [
{
header: "This is panel header 1 (showIcon:true)",
content: "This is panel content 1",
showIcon: true,
defaultActive: true,
},
{
header: "This is panel header 2 (showIcon:collapse-arrow)",
content: "This is panel content 2",
showIcon: "collapse-arrow",
},
{
header: "This is panel header 3(showIcon:collapse-plus)",
content: "This is panel content 3",
showIcon: "collapse-plus",
},
];
<Accordion name="demo-showIcon" items={items} />
This is panel header 1 (showIcon:true)
This is panel content 1
This is panel header 2 (showIcon:collapse-arrow)
This is panel content 2
This is panel header 3(showIcon:collapse-plus)
This is panel content 3

折叠面板模式

你可以通过 collapse 设置同时展开多个面板,这个例子默认展开了第一个。

const items = [
{
header:"This is panel header 1",
content: "This is panel content 1",
defaultActive: true,
},
{
header:"This is panel header 2",
content: "This is panel content 2",
showIcon: true,
},
{
header: "This is panel header 3",
content: "This is panel content 3",
showIcon: true,
},
];
<Accordion name="demo-collapse" collapse items={items} />
This is panel header 1
This is panel content 1
This is panel header 2
This is panel content 2
This is panel header 3
This is panel content 3

添加边框

你可以通过 bordered 设置外层边框。

const items = [
{
header: "This is panel header 1",
content: "This is panel content 1",
defaultActive: true,
},
{
header: "This is panel header 2",
content: "This is panel content 2",
},
{
header: "This is panel header 3",
content: "This is panel content 3",
},
];
<Accordion name="demo-bordered" items={items} />
This is panel header 1
This is panel content 1
This is panel header 2
This is panel content 2
This is panel header 3
This is panel content 3

紧凑风格( join 组合 Panel )

你可以通过 join 设置 Panel 元素紧凑风格的面板。
紧凑风格推荐使用 bordered 设置外层边框。

const items = [
{
header: "This is panel header 1",
content: "This is panel content 1",
defaultActive: true,
classes: {
container: "bg-transparent",
header: "",
content: "",
}
},
{
header: "This is panel header 2",
content: "This is panel content 2",
showIcon: true,
},
{
header: "This is panel header 3",
content: "This is panel content 3",
showIcon: true,
},
];
<Accordion
name="demo-collapse"
join
bordered
items={items}
classes={{
container: "",
panel:{
container: "bg-transparent",
header: "",
content: "",
}
}}
/>
This is panel header 1
This is panel content 1
This is panel header 2
This is panel content 2
This is panel header 3
This is panel content 3

API

Accordion

属性说明类型默认值
name所有同名 Accordion 一起时只有一个可以被选中。
如果你有超过一个 Accordion 手风琴在一个页面上,你需要给每一个 Accordion 设置不同的名字。
string""
items折叠项目内容ItemType[]
join是否启用紧凑风格。利用 join 组合 Panel 组件。
子组件 Panel 需同时传入 joinItem 属性。
booleanfalse
collapse是否同时展开多个面板(折叠面板模式)booleanfalse
bordered带边框风格的折叠面板booleanfalse
classes作用于 Accordion 的样式Accordion.classes-

Accordion.classes

属性说明类型默认值
containerPanel 最外层元素样式string""
panel作用于 Panel 组件的通用样式,优先级低于 ItemType.classesobject-

ItemType ( Panel )

属性说明类型默认值
header面板头内容string""
defaultActive初始化选中的面板booleanfalse
showIcon是否展示当前面板上的 Icon,可选值有 collapse-arrow collapse-plus
showIcon=true时,默认使用 collapse-arrow
boolean || string”collapse-arrow”
content面板内容文本string""
classes组件的样式ItemType.classes-

ItemType.classes

属性说明类型默认值
containerPanel 最外层元素样式string""
headerPanel 标题样式string""
contentPanel 内容区域样式string""