跳转到内容

Accordion API

想要学习更多组件属性和 CSS API,可以查阅 React Accordion 组件的 API 文档。

导入

import Accordion from '@mui/material/Accordion';
// 或
import { Accordion } from '@mui/material';
You can learn about the difference by reading this guide on minimizing bundle size.

组件名称

The name MuiAccordion can be used when providing default props or style overrides in the theme.

属性

Paper 组件的属性也是可用的。

名称类型默认值描述
children*node
组件的内容
classesobject
覆盖或扩展应用于组件的样式。请参阅下面 CSS API 了解更多详情。
defaultExpandedboolfalse
如果 true, 自动打开折叠面板。
disabledboolfalse
如果被设置为 true,那么该组件将会被禁用。
disableGuttersboolfalse
如果 true, 它会移除两个打开的折叠面板的边距和增加的高度。
expandedboolfalse
如果 true, 则打开折叠面板, 否则关闭折叠面板。 设置此属性允许控制折叠面板.
onChangefunc
Callback fired when the expand/collapse state is changed.

Signature:
function(event: object, expanded: boolean) => void
event: The event source of the callback. Warning: This is a generic event not a change event.
expanded: The expanded state of the accordion.
squareboolfalse
如果 true, 圆角将被禁用。
sxArray<func
| object
| bool>
| func
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
TransitionComponentelementTypeCollapse
The component used for the transition. Follow this guide to learn more about the requirements for this component.
TransitionPropsobject
Props applied to the transition element. By default, the element is based on this Transition component.

ref 则会被传递到根元素中。

继承

While not explicitly documented above, the props of the Paper component are also available on Accordion. You can take advantage of this to target nested components.

CSS

规则名称全局类名描述
root.MuiAccordion-root用于根元素的样式。
rounded.MuiAccordion-rounded除非 square={true},样式适用于 根元素 。
expanded.Mui-expanded如果满足expanded={true},状态类将适用于根元素
disabled.Mui-disabled如果满足disabled={true},状态类将适用于根元素
gutters.MuiAccordion-gutters除非 disableGutters={true},样式适用于 根元素 。
region.MuiAccordion-region适用于 区域元素, 子组件的容器 的样式。

您可以使用组件自定义选项对组件进行个性化:

演示项目