# Avatar group

> Overlapping row of avatars that collapses extra people into a "+N" chip after a chosen limit.

- Kind: ui · Category: Data display · Interactivity: none
- Install: `npx shadcn@latest add @haze/avatar-group`
- File: `src/components/haze/ui/avatar-group.astro`
- npm dependencies: none
- Registry dependencies: @haze/avatar, @haze/utils
- Docs page: https://hazeui.com/ui/avatar-group

## Use when
- Showing who is on a project, a document or a meeting in a small space
- Teams of unknown size, where only the first few faces fit
- Cards and table rows that need a compact member list

## Avoid when
- Readers need every name in view; list the people instead
- A single person; use avatar

## Alternatives
- [avatar](https://hazeui.com/ui/avatar.md)
- [tag](https://hazeui.com/ui/tag.md)
- [item](https://hazeui.com/ui/item.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| people | `{ name: string; src?: string }[]` |  | yes | People in order; each avatar shows the initials of its name, or the photo when src is set. |
| max | `number` | 4 | no | Avatars shown before the overflow chip. |
| size | `"sm" \| "md" \| "lg"` | "md" | no | Passed to every avatar and to the chip. |
| label | `string` |  | no | Accessible name of the group; defaults to a member count such as "5 members". |
| moreLabel | `string` | "more" | no | Screen-reader word after the overflow count, so "+4" is read as "4 more". Translate it for other languages. |
| class | `string` |  | no | Extra classes on the group. |

## Accessibility
- The group has role="group" and a label with the full count, so the total is known even when the chip hides most names.
- Each avatar is announced by its full name and the chip as "3 more" (or the moreLabel you pass); the initials alone are never the only text.
- The ring in the page background keeps overlapping avatars distinct without relying on their fill colors.

## Agent prompts

### Install and use

Install the Haze UI component "Avatar group" with `npx shadcn@latest add @haze/avatar-group`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AvatarGroup from "@/components/haze/ui/avatar-group.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/avatar-group.md

### Customize with real content

Adapt the Haze avatar-group ui for our product. Replace the demo values of these props with our real content: people, max, size, label, moreLabel, class. Keep the layout, the heading level rules and these accessibility details: The group has role="group" and a label with the full count, so the total is known even when the chip hides most names. Each avatar is announced by its full name and the chip as "3 more" (or the moreLabel you pass); the initials alone are never the only text. The ring in the page background keeps overlapping avatars distinct without relying on their fill colors. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using avatar-group, check it fits: use it when showing who is on a project, a document or a meeting in a small space; teams of unknown size, where only the first few faces fit; cards and table rows that need a compact member list. Avoid it when readers need every name in view; list the people instead; a single person; use avatar. Alternatives: @haze/avatar, @haze/tag, @haze/item.

## Example requests that should lead here
- Show five teammates as an avatar group with a plus chip
- Use a small avatar group in the card footer labelled Reviewers

## Source

```astro
---
import { cn } from "../../../lib/haze/utils";
import Avatar from "./avatar.astro";

interface Props {
  /** People in order. src is an optional photo URL. */
  people: { name: string; src?: string }[];
  /** Most avatars to show before the "+N" chip. */
  max?: number;
  size?: "sm" | "md" | "lg";
  /** Accessible name of the group. Defaults to the member count. */
  label?: string;
  /** Screen-reader word after the overflow count, so "+4" is read as "4 more". Translate it for other languages. */
  moreLabel?: string;
  class?: string;
}

const { people, max = 4, size = "md", label, moreLabel = "more", class: className } = Astro.props;
const limit = Math.max(Math.floor(max), 0);
const shown = people.slice(0, limit);
const extra = people.length - shown.length;
const groupLabel = label ?? `${people.length} ${people.length === 1 ? "member" : "members"}`;
const chipSizes = { sm: "size-6 text-[0.625rem]/4", md: "size-8 text-xs/4", lg: "size-10 text-sm/5" };
// Overlap scales with size; the 2 px background ring separates neighbours without touching the initials.
const overlaps = { sm: "-space-x-1", md: "-space-x-1.5", lg: "-space-x-2" };
---

<div role="group" aria-label={groupLabel} class={cn("flex", overlaps[size], className)}>
  {
    shown.map((person) => (
      <Avatar
        name={person.name}
        src={person.src}
        size={size}
        class="ring-2 ring-background"
      />
    ))
  }
  {
    extra > 0 && (
      <span
        role="img"
        aria-label={`${extra} ${moreLabel}`}
        class={cn(
          "relative inline-flex shrink-0 items-center justify-center rounded-full bg-muted font-medium text-foreground tabular-nums inset-ring inset-ring-frame ring-2 ring-background",
          chipSizes[size],
        )}
      >
        +{extra}
      </span>
    )
  }
</div>
```
