Files
heroui-vue/apps/docs/components/header.md
T

106 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: Header 标题
description: 集合或分组的区块标题部件,用于菜单、列表等结构中的分组说明。
component: header
group: 组件
---
## 用法
```vue
<script setup lang="ts">
import { Header } from "@heroui-vue/components";
</script>
<template>
<Header>操作</Header>
</template>
```
<ComponentPreview name="header-basic" />
> **说明:** 固定 HeroUI 基线没有独立的 Header 中文组件页或专属演示目录。本页与下方示例为自编,用于说明语义、默认样式与自定义方式;不是官方文案的完整复刻。
## 组件结构
`Header` 是集合/分组标题部件,不是带 Logo、导航和用户菜单的应用顶栏。固定基线的 React Aria Components `Header` 渲染原生 `<header>` 元素(不是任意 heading 级别),常出现在 Dropdown、ListBox、ComboBox、Autocomplete 的分组中。
Vue 版导出 `Header` 与 `HeaderRoot`(同一实现)。菜单 / ListBox 尚未迁移时,可用语义容器解释组合边界,例如在分组列表或表单分区前放置标题:
<ComponentPreview name="header-semantic" />
```vue
<script setup lang="ts">
import { Header } from "@heroui-vue/components";
</script>
<template>
<section>
<Header>发票列表</Header>
<ul>
<li>INV-1001</li>
</ul>
</section>
</template>
```
## 示例
### 自定义 class
<ComponentPreview name="header-custom-class" />
`class` 合并到 `<header>` 根元素,可覆盖字号、颜色与间距。
## 自定义样式
### 全局 CSS
```css
@layer components {
.hv-header {
@apply text-sm font-semibold text-foreground;
}
}
```
## 样式参考
类名前缀为 `hv-`。
### CSS 类
- `.hv-header` - 根元素(`w-full px-2 pt-1.5 pb-1 text-start text-xs font-medium text-muted`)
## API 参考
### Header / HeaderRoot
| Prop | 类型 | 默认值 | 描述 |
| -------- | --------------------------- | ---------- | ---------------- |
| `as` | `string` | `'header'` | 自定义根元素标签 |
| `class` | `string \| Array \| Object` | - | 附加 CSS 类 |
| 默认插槽 | - | - | 标题内容 |
根元素同时接收其余 `$attrs`(`aria-*`、`data-*`、`id`、`style`、事件等)。本组件没有业务值,不提供 `v-model`、表单提交或焦点状态。
### 上游差异
| 上游 React 能力 | Vue 实现 |
| --------------------------- | ------------------------------------------ |
| `Header.Root` 对象子部件 | 独立具名导出 `Header` / `HeaderRoot` |
| RAC Collection 叶子节点 | 语义 HTML 封装;集合上下文由未来菜单族提供 |
| `className` / `children` | `class` / 默认插槽 |
| `render` / `DOMRenderProps` | `as` 更换元素,属性直接透传 |
## 无障碍
- 默认渲染原生 `<header>`,与固定基线 RAC Header 一致;不强制 heading 级别。
- 不自动附加 `role` 或 `aria-level`;分组语义由所在集合(Menu / ListBox 等)提供。需要文档标题层级时,请在应用侧使用真正的 `h1`–`h6` 或 `aria-labelledby`。
- 真实读屏表现未在本轮验证。
## 相关组件
- [Typography 排版](./typography)
- [EmptyState 空状态](./empty-state)