Skip to Content
文档

折叠面板

用于显示和隐藏页面上的相关内容部分

SourceStorybookRecipeArk
Some value 2...

用法

¥Usage

import { Accordion } from "@chakra-ui/react"
<Accordion.Root>
  <Accordion.Item>
    <Accordion.ItemTrigger>
      <Accordion.ItemIndicator />
    </Accordion.ItemTrigger>
    <Accordion.ItemContent>
      <Accordion.ItemBody />
    </Accordion.ItemContent>
  </Accordion.Item>
</Accordion.Root>

示例

¥Examples

受控

¥Controlled

设置默认显示的手风琴面板。

¥Set the accordion that shows up by default.

Expanded: second-item

Some value 2...

包含图标

¥With Icon

以下是在每个折叠面板项目中渲染自定义图标的示例。

¥Here's an example of rendering a custom icon in each accordion item.

Product details

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur nec odio vel dui euismod fermentum.

展开多个项目

¥Expand Multiple Items

使用 multiple 属性可允许一次展开多个项目。

¥Use the multiple prop to allow multiple items to be expanded at once.

Some value 2...

尺寸

¥Sizes

使用 size 属性更改手风琴面板的大小。

¥Use the size prop to change the size of the accordion.

sm

Some value 2...

md

Some value 2...

lg

Some value 2...

变量

¥Variants

使用 variant 属性更改手风琴面板的视觉样式。值可以是 outlinesubtleenclosedplain

¥Use the variant prop to change the visual style of the accordion. Values can be either outline, subtle, enclosed or plain.

outline

Some value 2...

subtle

Some value 2...

enclosed

Some value 2...

plain

Some value 2...

已禁用项目

¥Disabled Item

disabled 属性传递给任何 Accordion.Item 组件,以防止其展开或折叠。

¥Pass the disabled prop to any Accordion.Item to prevent it from being expanded or collapsed.

Some value 2...

包含头像

¥With Avatar

以下是将手风琴面板与头像组合的示例。

¥Here's an example of composing an accordion with an avatar.

包含辅助文本

¥With Subtext

这是一个向折叠面板项目添加子文本的示例。

¥Here's an example of adding a subtext to an accordion item.

包含动作

¥With Actions

这是一个向折叠面板项目触发器添加操作的示例。

¥Here's an example of adding actions to an accordion item trigger.

Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos.

属性

¥Props

根元素

¥Root

PropDefaultType
collapsible false
boolean

Whether an accordion item can be closed after it has been expanded.

lazyMount false
boolean

Whether to enable lazy mounting

multiple false
boolean

Whether multiple accordion items can be expanded at the same time.

orientation '\'vertical\''
'horizontal' | 'vertical'

The orientation of the accordion items.

unmountOnExit false
boolean

Whether to unmount on exit.

colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'

The color palette of the component

variant 'outline'
'outline' | 'subtle' | 'enclosed' | 'plain'

The variant of the component

size 'md'
'sm' | 'md' | 'lg'

The size of the component

as
React.ElementType

The underlying element to render.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
unstyled
boolean

Whether to remove the component's style.

defaultValue
string[]

The initial value of the expanded accordion items. Use when you don't need to control the value of the accordion.

disabled
boolean

Whether the accordion items are disabled

id
string

The unique identifier of the machine.

ids
Partial<{ root: string item: (value: string) => string itemContent: (value: string) => string itemTrigger: (value: string) => string }>

The ids of the elements in the accordion. Useful for composition.

onFocusChange
(details: FocusChangeDetails) => void

The callback fired when the focused accordion item changes.

onValueChange
(details: ValueChangeDetails) => void

The callback fired when the state of expanded/collapsed accordion items changes.

value
string[]

The controlled value of the expanded accordion items.

项目

¥Item

PropDefaultType
value *
string

The value of the accordion item.

as
React.ElementType

The underlying element to render.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
disabled
boolean

Whether the accordion item is disabled.

Previous

时间轴

Next

面包屑