145a208687
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
113 lines
3.0 KiB
Markdown
113 lines
3.0 KiB
Markdown
---
|
||
title: Description 描述
|
||
description: 为表单字段及其他组件提供补充说明文本
|
||
component: description
|
||
group: 组件
|
||
---
|
||
|
||
## 用法
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { Description, Input, Label } from "@heroui-vue/components";
|
||
</script>
|
||
```
|
||
|
||
<ComponentPreview name="description-basic" />
|
||
|
||
## 示例
|
||
|
||
### 搭配表单字段
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { Description, Input, Label } from "@heroui-vue/components";
|
||
</script>
|
||
|
||
<template>
|
||
<div class="flex flex-col gap-1">
|
||
<Label for="password">密码</Label>
|
||
<Input
|
||
id="password"
|
||
type="password"
|
||
aria-describedby="password-description"
|
||
/>
|
||
<Description id="password-description">
|
||
至少 8 个字符,且包含一个大写字母
|
||
</Description>
|
||
</div>
|
||
</template>
|
||
```
|
||
|
||
### 与 TextField 配合
|
||
|
||
```vue
|
||
<script setup lang="ts">
|
||
import { TextField, Label, Input, Description } from "@heroui-vue/components";
|
||
</script>
|
||
|
||
<template>
|
||
<TextField type="email">
|
||
<Label>邮箱</Label>
|
||
<Input placeholder="输入你的邮箱" />
|
||
<Description>我们不会分享你的邮箱</Description>
|
||
</TextField>
|
||
</template>
|
||
```
|
||
|
||
使用 [TextField](/components/text-field) 时,`aria-describedby` 会自动合并到控件;支持多个描述与动态 id。
|
||
|
||
## 自定义样式
|
||
|
||
### Tailwind CSS
|
||
|
||
<ComponentPreview name="description-custom-styles" />
|
||
|
||
### 全局 CSS
|
||
|
||
可使用 `@layer components` 指令自定义 Description 组件类。
|
||
|
||
```css
|
||
@layer components {
|
||
.hv-description {
|
||
@apply text-muted;
|
||
}
|
||
}
|
||
```
|
||
|
||
## 样式参考
|
||
|
||
HeroUI 遵循 [BEM](https://getbem.com/) 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 `hv-`。
|
||
|
||
### CSS 类
|
||
|
||
Description 组件使用以下 CSS 类([查看源码样式](https://github.com/heroui-inc/heroui/blob/v3/packages/styles/components/description.css)):
|
||
|
||
#### 基础类 [!toc]
|
||
|
||
- `.hv-description` - 基础描述样式,使用 `muted` 文本颜色
|
||
|
||
## API 参考
|
||
|
||
### Description
|
||
|
||
| Prop | 类型 | 默认值 | 描述 |
|
||
| -------- | --------------------------- | ------ | --------------------------------- |
|
||
| `id` | `string` | 自动 | 显式 id;未指定时生成并与控件关联 |
|
||
| 默认插槽 | `Component` | - | 描述内容 |
|
||
| `class` | `string \| Array \| Object` | - | 附加 CSS 类(Vue class 绑定) |
|
||
|
||
## 无障碍
|
||
|
||
Description 组件通过以下方式增强无障碍性:
|
||
|
||
- 使用屏幕阅读器可识别的语义化 HTML(`p`)
|
||
- 在 TextField 内自动注册到控件的 `aria-describedby`
|
||
- 支持多个描述、外部 `aria-describedby` 合并与卸载清理
|
||
|
||
任意用户 Vue 包装组件不能被 TextField 静态展开做 SSR 预规划;需要首屏 SSR 关联时请显式设置控件 `aria-describedby` 与描述 id。
|
||
|
||
## 相关组件
|
||
|
||
[TextField 文本输入框](./text-field) · [Input 输入框](./input) · [TextArea 多行文本框](./textarea)
|