Files
heroui-vue/apps/docs/components/avatar-group.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.7 KiB
Raw Blame History

title, description, component, group
title description component group
AvatarGroup 头像组 以叠放或网格展示多个头像,并支持溢出计数 avatar-group 组件

用法

<script setup lang="ts">
import {
  Avatar,
  AvatarGroup,
  AvatarImage,
  AvatarFallback,
} from "@heroui-vue/components";
</script>

组件结构

<script setup lang="ts">
import {
  Avatar,
  AvatarGroup,
  AvatarGroupCount,
  AvatarImage,
  AvatarFallback,
} from "@heroui-vue/components";
</script>

<template>
  <AvatarGroup>
    <Avatar>
      <AvatarImage />
      <AvatarFallback />
    </Avatar>
    <AvatarGroupCount><!-- 可选的显式子组件 --></AvatarGroupCount>
  </AvatarGroup>
</template>

示例

最大数量

自定义计数

尺寸

网格

叠放样式(Overlap)

自定义样式

Tailwind CSS

全局 CSS

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

@layer components {
  .hv-avatar-group {
    --avatar-group-overlap: 0.75rem;
    --avatar-group-seam: 2px;
  }

  .hv-avatar-group__count {
    @apply font-semibold;
  }
}

样式参考

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

CSS 类

AvatarGroup 组件使用以下 CSS 类:

基础类 [!toc]

  • .hv-avatar-group - 头像组基础容器
  • .hv-avatar-group--grid - 网格布局修饰符(无叠放)
  • .hv-avatar-group--clip - 新月裁切 / 透明缝(默认叠放)
  • .hv-avatar-group--ring - 通过 --background 的实线 box-shadow 描边
  • .hv-avatar-group__count - 溢出计数头像

叠放布局在兄弟元素之间使用负外边距(--avatar-group-overlap,默认 0.5rem)。clip 模式对非末子头像做遮罩,并光学微调 fallback 字形;ring 模式使用 --background 细线 box-shadow 描边。

API 参考

AvatarGroup

Prop 类型 默认值 描述
size 'sm' | 'md' | 'lg' 'md' 当子 Avatar 未指定 size 时应用到子头像(及溢出计数);默认与 Avatar 一致
color 'default' | 'accent' | 'success' | 'warning' | 'danger' - 当子 Avatar 未指定 color 时,应用到子头像(及溢出计数)的颜色
variant 'default' | 'soft' - 当子 Avatar 未指定 variant 时,应用到子头像(及溢出计数)的变体
max number - 最多渲染的头像子项数量;省略则显示全部
isGrid boolean false 是否使用无叠放的换行网格布局
overlap 'clip' | 'ring' 'clip' 叠放样式:新月裁切(默认)或 box-shadow 描边;isGrid 时忽略
class string - 附加 CSS 类
默认插槽 Avatar[] | AvatarGroupCount - 要组合的 Avatar 组件(以及可选的 AvatarGroupCount)

AvatarGroupCount

由 Avatar + AvatarFallback 组合而成,用于溢出指示。不受 max 截断。

Prop 类型 默认值 描述
默认插槽 string | Component - 计数内容(例如 +3)
size 'sm' | 'md' | 'lg' - 覆盖组的尺寸
color 'default' | 'accent' | 'success' | 'warning' | 'danger' - 覆盖组的颜色
variant 'default' | 'soft' - 覆盖组的变体
class string - 附加 CSS 类

注意事项

  • AvatarGroup 通过 provide/inject 仅向直接 Avatar 子组件传递 size、color 与 variant
  • 设置 max 会截断可见头像并根据剩余子项自动计数;省略则显示全部
  • 已知总量(例如来自服务端)时,渲染显式的 AvatarGroupCount — 它不受 max 截断,并会抑制自动计数。请用 Count 替代已移除的 v2 total
  • isGrid 会禁用叠放,改为换行网格布局
  • overlap 默认为 "clip"(新月裁切);使用 "ring" 可改为实线描边;与 isGrid 同时使用时无效
  • 默认不加 role="group" — 当叠放有语义(指派人、在看的人)时,自行加上 role="group",并配合 aria-label 或 aria-labelledby

相关组件

Avatar 头像 · Badge 徽章 · Chip 标签