Files
heroui-vue/apps/docs/components/description.md
T
maoyingjie dc859fb8ae feat(styles): export shared field variant maps and restore the border fallback
HD-05 scope, against heroui ce90ea3 styles sources:

- add labelVariants/descriptionVariants/fieldErrorVariants/
  textFieldVariants/switchGroupVariants (+ VariantProps types) to
  @heroui-vue/styles and re-export them from @heroui-vue/components;
  variant keys, defaultVariants and slot sets match the pinned
  *.styles.ts files key for key (hv- namespace only)
- Label/Description/FieldError/useTextField/SwitchGroup now consume
  those mappings instead of inline class strings, so the state classes
  have a single source; rendered class output is unchanged and pinned
  by tests/shared-field-styles.test.ts (mapping output <-> component
  output)
- restore the global border-color fallback
  (*, ::after, ::before, ::backdrop, ::file-selector-button ->
  border-color: var(--border, currentColor)) in a new base/base.css,
  imported layer(base) right after preflight like the pinned entry:
  a low-priority default that components, utilities and consumer CSS
  override without !important
- view-transition globals from the pinned base.css stay unported: no
  View Transitions API usage exists in the library or docs site
- shared-styles package contract: packed runtime exports from both
  entries, variant-output assertions, CSS tokens incl. the fallback,
  strict nodenext+bundler type contract, and a real-browser consumer
  fixture (light/dark --border, explicit colors, consumer overrides,
  currentColor fallback) wired into check-package.mjs
- docs: styling layers/border fallback/exports notes, five component
  API pages, compatibility matrix and upstream source records

Full suite 111 files / 1634 tests, typecheck and build:docs pass;
shared-styles + api-root-aliases + handbook-styles verified against
the final tarballs.
2026-10-28 23:36:59 +08:00

3.2 KiB
Raw Blame History

title, description, component, group
title description component group
Description 描述 为表单字段及其他组件提供补充说明文本 description 组件

用法

<script setup lang="ts">
import { Description, Input, Label } from "@heroui-vue/components";
</script>

示例

搭配表单字段

<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 配合

<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 时,aria-describedby 会自动合并到控件;支持多个描述与动态 id。

自定义样式

Tailwind CSS

全局 CSS

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

@layer components {
  .hv-description {
    @apply text-muted;
  }
}

样式参考

HeroUI 遵循 BEM 方法论,确保组件变体与状态可复用且易于自定义。类名前缀为 hv-。

CSS 类

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

变体映射 descriptionVariants 从 @heroui-vue/styles 公开(@heroui-vue/components 再导出同一函数与 DescriptionVariants 类型);组件渲染的类名由该映射生成。

基础类 [!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 文本输入框 · Input 输入框 · TextArea 多行文本框