AvatarGroup
Groups data-driven or slotted avatars and summarizes excess items.
Import
Use <hui-avatar-group> after configuring uni-app easycom. Import public types and functions from @nscode/handy-uni. Ordinary Vue applications install the @nscode/handy-uni/web preview plugin.
Examples
Each example is standalone. Controls show the current value or event result on the page.
<template>
<view>
<hui-space direction="vertical" fill>
<hui-avatar-group
custom-class="hui-space__item"
:items="people"
:max="2"
@click="(_, context) => (lastEvent = String(context.index))"
@excess-click="(context) => (lastEvent = String(context.hidden.length))"
/>
<hui-avatar-group custom-class="hui-space__item" :overlap="false" size="small" shape="square"
><hui-avatar label="甲" /><hui-avatar label="乙"
/></hui-avatar-group>
<text class="hui-space__item">{{ lastEvent }}</text>
</hui-space>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('尚无事件 / No event')
const people = [
{ id: 1, label: '甲' },
{ id: 2, label: '乙' },
{ id: 3, label: '丙' }
]
</script>
Props
| Prop | Type | Default | Details |
|---|---|---|---|
items | AvatarGroupItem[] | — | Data items rendered in source order. |
max | number | — | Maximum visible items; remaining items use the excess entry. |
size | AvatarSize | 'default' | Named component size or an explicit pixel size. |
shape | AvatarShape | 'circle' | Visual shape. |
overlap | boolean | true | Overlaps neighboring avatars. |
itemKey | string | ((item: AvatarGroupItem) => string | number) | — | Stable object field or key getter; falls back to id, then index. |
Root classes and styles use customClass and customStyle. Numbers representing dimensions use px; durations use ms unless explicitly documented.
Events
| Event | Arguments |
|---|---|
click | (item: AvatarGroupItem, context: { index: number }) |
excess-click | (context: { hidden: AvatarGroupItem[] }) |
Controlled state only changes when the parent accepts its update event. Events with multiple words use kebab-case. Disabled or stale asynchronous actions do not emit a successful state change.
Slots
| Slot | Scope |
|---|---|
item | { item, index } |
excess | { count, hidden } |
default | — |
Methods
None.
Types
AvatarGroupItem、AvatarGroupProps、AvatarGroupEmits.
Platform notes
Supports H5, WeChat mini-program, App-vue and ordinary Vue 3 Web through shared platform components. Unit tests do not replace device acceptance; verify touch, screen readers, deactivation and native rendering on each target.
Device smoke checklist.