ProComponents, templates & AI tooling
HeroUI
27.7k

DisclosureGroup 折叠面板组

管理多个 Disclosure 项展开状态的容器

用法

import { DisclosureGroup } from '@heroui/react';

组件结构

import {DisclosureGroup, Disclosure} from '@heroui/react';

export default () => (
  <DisclosureGroup>
    <Disclosure id="item1">
      <Disclosure.Heading>
        <Disclosure.Trigger>
          <Disclosure.Indicator />
        </Disclosure.Trigger>
      </Disclosure.Heading>
      <Disclosure.Content />
    </Disclosure>
  </DisclosureGroup>
)

示例

受控组件

可使用 expandedKeysonExpandedChange props 配合外部导航控件控制哪些 Disclosure 处于展开状态。

自定义样式

Tailwind CSS

全局 CSS

可使用 @layer components 指令自定义 DisclosureGroup 组件类。 了解更多

@layer components {
  .disclosure-group {
    @apply w-full;

    /* Performance optimization */
    contain: layout style;
  }
}

样式参考

HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。

CSS 类

DisclosureGroup 组件使用以下 CSS 类(查看源码样式):

基础类

  • .disclosure-group - 基础容器样式,含布局 containment

交互状态

组件同时支持 CSS 伪类与 data 属性:

  • Disabled:整个分组上 :disabled[aria-disabled="true"]
  • Expanded Management:自动管理子 Disclosure 项上的 [data-expanded] 状态

API 参考

DisclosureGroup

Prop类型默认值描述
expandedKeysSet<Key>-当前展开项(受控)
defaultExpandedKeysIterable<Key>-初始展开项(非受控)
onExpandedChange(keys: Set<Key>) => void-展开项变化时的回调
allowsMultipleExpandedbooleanfalse是否允许多项同时展开
isDisabledbooleanfalse是否禁用组内所有 Disclosure
childrenReactNode | RenderFunction-要渲染的 Disclosure 项
classNamestring-附加 CSS 类

Render Props

使用 render prop 模式时,提供以下值:

Prop类型描述
expandedKeysSet<Key>当前展开项的 key
isDisabledboolean分组是否禁用

相关案例

相关组件

本页目录