Files
heroui-vue/apps/docs/components/disclosure.md
T
maoyingjie 145a208687 docs: close documentation facts, structure and related-component mapping
HD-04 scope, against heroui ce90ea3 cn sources:

- stale/fictional content: input.md no longer claims TextField is
  unmigrated; color-field.md no longer claims ColorPicker is private;
  header.md drops the fictional Header.Root subcomponent and the stale
  'menus not migrated' wording (MenuSection label registration is now
  documented from HeaderRoot source); radio-group.md drops three copied
  CheckboxGroup wordings (variant override is Radio's, scalar emits,
  native single-value submit); input-otp.md drops the fictional
  data-complete state and lists the real missing upstream props
- toggle-button disabled row now matches the real CSS hooks
  (:disabled / [aria-disabled], with data-disabled as a marker only)
- part API / CSS classes / interactive states restored per pinned
  sources: button (full class lists + real variable-based global CSS),
  accordion (per-part tables + variant/state lists), card (per-part
  tables + variant list), switch (SwitchGroup snippet + Switch/
  SwitchGroup class lists + states), color-field Group (class list +
  states), input-otp (variant notes, global CSS, class/state lists);
  input-group gains the two upstream usage chapters
- RelatedComponents restored from the pinned componentRelationships
  (first-3, filtered against componentsMap): 64 pages rewritten,
  list-box/slider sections added, 7 empty-mapping pages' fabricated
  entries removed; RelatedShowcases left unmigrated with its real data
  inventory recorded (2 cases, showcase-site cards)
- defaults unified on implementation evidence: granularity (inferred
  day/minute) and visibleYears (full min-max span, no "or 20" fallback);
  HD-03 hand-offs resolved (trigger focus-visible noted for HD-06,
  width guards kept)
- new demos: header-collection-grouping (MenuSection/ListBoxSection
  label wiring), empty-state-collection (collection empty slot);
  empty-state page deduplicated with a boundary compatibility note
- ComponentPreview minHeight/isBgSolid restored per the 30 upstream
  marks; tabs-overflow max-w-full kept after measuring internal scroll
- tests: +3 header registration/demo cases, +1 empty-state collection
  case; full suite 110 files / 1630 tests, typecheck and build:docs
  pass
2026-10-28 22:32:10 +08:00

5.6 KiB
Raw Blame History

title, description, component, group
title description component group
Disclosure 折叠面板 可折叠区块,包含标题、触发按钮与内容面板 disclosure 组件

用法

<script setup lang="ts">
import {
  Disclosure,
  DisclosureContent,
  DisclosureHeading,
  DisclosureIndicator,
  DisclosureTrigger,
} from "@heroui-vue/components";
</script>

<template>
  <Disclosure>
    <DisclosureHeading>
      <DisclosureTrigger>
        标题
        <DisclosureIndicator />
      </DisclosureTrigger>
    </DisclosureHeading>
    <DisclosureContent>
      <p>内容</p>
    </DisclosureContent>
  </Disclosure>
</template>

组件结构

<script setup lang="ts">
import {
  Disclosure,
  DisclosureContent,
  DisclosureHeading,
  DisclosureIndicator,
  DisclosureTrigger,
} from "@heroui-vue/components";
</script>

<template>
  <Disclosure>
    <DisclosureHeading>
      <DisclosureTrigger>
        <DisclosureIndicator />
      </DisclosureTrigger>
    </DisclosureHeading>
    <DisclosureContent />
  </Disclosure>
</template>

Disclosure 渲染为带 data-slot="disclosure" 的容器。DisclosureTrigger 默认是 type="button" 的按钮,点击/Enter/Space 切换展开;as-child 可把触发语义合并到 Button 等单个子元素。

示例

渲染函数

上游 render 用于替换根元素;Vue 版通过 as 更换元素类型,data-* 等属性直接透传。

自定义样式

Tailwind CSS

全局 CSS

可使用 @layer components 指令自定义 Disclosure 组件类。

@layer components {
  .hv-disclosure {
    @apply relative;
  }

  .hv-disclosure__trigger {
    @apply cursor-pointer;
  }

  .hv-disclosure__indicator {
    @apply transition-transform duration-300;
  }

  .hv-disclosure__content {
    @apply overflow-hidden transition-all;
  }
}

样式参考

HeroUI 遵循 BEM 方法论。类名前缀为 hv-。

CSS 类

  • .hv-disclosure - 基础容器样式
  • .hv-disclosure__heading - 标题包裹层
  • .hv-disclosure__trigger - 触发按钮样式
  • .hv-disclosure__indicator - 箭头指示器样式
  • .hv-disclosure__content - 带动画的内容容器
  • .hv-disclosure__body / .hv-disclosure__body-inner - 正文与内层

交互状态

  • Expanded:指示器上 [data-expanded="true"] 用于旋转;内容上 [data-expanded="true"]
  • Focus:触发器上 :focus-visible
  • Disabled:触发器上 :disabled 或 [aria-disabled="true"]
  • 内容高度使用测量变量驱动展开动画,并支持 prefers-reduced-motion

API 参考

Disclosure

属性 类型 默认值 描述
id string | number - 组键与 DOM id
expanded boolean - 受控展开状态;配合 v-model:expanded
defaultExpanded boolean false 非受控初始展开
isDisabled boolean false 是否禁用
as string "div" 根元素类型
class string | Array | Object - 合并到根元素
默认插槽 { isExpanded, isDisabled } - 内容或作用域插槽

事件:update:expanded、expandedChange。

DisclosureHeading

属性 类型 默认值 描述
as string "h3" 标题元素
level 1–6 3 标题级别
class string | Array | Object - 合并到标题元素

DisclosureTrigger

属性 类型 默认值 描述
as string "button" 元素类型
asChild boolean false 合并到默认插槽的单个子元素
isDisabled boolean false 禁用触发
class string | Array | Object - 合并到触发器
默认插槽 { isExpanded, isDisabled } - 触发器内容

事件:click(可在处理函数中 preventDefault 取消切换)。

DisclosureContent

属性 类型 默认值 描述
as string "div" 面板元素
class string | Array | Object - 合并到面板
默认插槽 { isExpanded, isDisabled } - 面板内容

DisclosureBody / DisclosureIndicator

Body 提供基线内边距与内层包装。Indicator 默认为基线 Chevron 图标,可传入自定义图标作为默认插槽;展开时附加 data-expanded="true" 并旋转。

相关组件

Accordion 手风琴 · DisclosureGroup 折叠面板组 · Button 按钮