AvatarGroup
A row of avatars (role="group"; name it with aria-label), laid out as a stack (overlapping), spread or pie (layout). size reaches the members.
With max, the avatars beyond the limit are replaced by an overflow <button> ("+3", named "3 more", see overflowLabel; overflowIndicator="icon" shows an icon, and a count above 99 reads "99+"). It toggles a popup that lists the hidden members: an AvatarGroup.Item as a row with its avatar and name, an Avatar by its aria-label or name prop, text as it is. Other members, such as an Avatar inside a link or one labelled by aria-labelledby, are rendered as they are, and an Avatar or text with no accessible name is listed as unnamedMemberLabel with a development warning. Focus moves into the popup; Escape, a press outside or the button close it and focus returns to the button (open, defaultOpen and onOpenChange(open, details) control it). Tab and Shift+Tab move through the popup's own tab stops (links in rendered members); Tab from the last one closes the popup and moves on to the element after the button, Shift+Tab from the first one closes it and returns to the button. When the button is the last tab stop (of the page, or of the Wave layer the group is in, such as a dialog), Tab is left to the browser or the enclosing focus trap.
To split the members yourself, render AvatarGroup.Items and an AvatarGroup.Popover holding the overflow items (see partitionAvatarGroupItems).
Examples
Default
export const Default: Story = {};Max Overflow
export const MaxOverflow: Story = {
args: {
max: 3,
},
};Small
export const Small: Story = {
args: {
max: 2,
size: 'small',
},
};Layouts
export const Layouts: Story = {
render: (args) => (
<div className="flex flex-wrap items-center gap-8">
{(['stack', 'spread', 'pie'] as const).map((layout) => (
<AvatarGroup key={layout} {...args} layout={layout} aria-label={`Team, ${layout}`}>
{PEOPLE.slice(0, 4).map((name) => (
<Avatar key={name} name={name} color="colorful" />
))}
</AvatarGroup>
))}
</div>
),
};Sizes
export const Sizes: Story = {
render: (args) => (
<div className="flex flex-col gap-3">
{(['small', 'medium', 'large'] as const).map((size) => (
<AvatarGroup key={size} {...args} size={size} max={3} aria-label={`Team, ${size}`}>
{PEOPLE.map((name) => (
<Avatar key={name} name={name} />
))}
</AvatarGroup>
))}
</div>
),
};Overflow Indicators
export const OverflowIndicators: Story = {
render: (args) => (
<div className="flex items-center gap-8">
<AvatarGroup {...args} max={2} overflowIndicator="icon" aria-label="Icon indicator">
{PEOPLE.map((name) => (
<Avatar key={name} name={name} />
))}
</AvatarGroup>
<AvatarGroup {...args} max={0} aria-label="Many members">
{Array.from({ length: 120 }, (_, i) => (
<Avatar key={i} name={`Member ${i + 1}`} />
))}
</AvatarGroup>
</div>
),
};Compound Form
export const CompoundForm: Story = {
render: (args) => {
const { inlineItems, overflowItems } = partitionAvatarGroupItems({
items: PEOPLE,
maxInlineItems: 2,
});
return (
<AvatarGroup {...args} aria-label="Project team">
{inlineItems.map((name) => (
<AvatarGroup.Item key={name} name={name} />
))}
{overflowItems && (
<AvatarGroup.Popover>
{overflowItems.map((name) => (
<AvatarGroup.Item key={name} name={name} />
))}
</AvatarGroup.Popover>
)}
</AvatarGroup>
);
},
};Motion
export const Motion: Story = {
render: function MotionPopups(args) {
return (
<div className="flex flex-wrap gap-4">
{motionCases(fadeAndZoom).map(({ label, motion }) => (
<AvatarGroup key={label} {...args} aria-label={label} max={2} motion={motion}>
{PEOPLE.map((name) => (
<Avatar key={name} name={name} size={args.size} />
))}
</AvatarGroup>
))}
</div>
);
},
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
max | number | No | Maximum number of avatars to display. The others are replaced by an overflow button that lists their names. | |
size | 'extra-small' | 'small' | 'medium' | 'large' | 'extra-large' | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128 | No | 'medium' ('large' in a `pie`) | Size of the avatars. It reaches the members that set no |
layout | 'stack' | 'spread' | 'pie' | No | 'stack' | How the members are laid out: |
overflowIndicator | 'count' | 'icon' | No | 'count' | What the overflow button shows: the number of hidden members ( |
overflowLabel | string | ((count: number) => string) | No | (count) => `${count} more` | Accessible name of the overflow button (and its popup). A function receives the number of hidden members. Localise it here. |
unnamedMemberLabel | string | No | 'Unnamed member' | Text listed in the overflow popup for a hidden member that has no accessible name (an |
open | boolean | No | Whether the overflow popup is open (controlled). | |
defaultOpen | boolean | No | false | Whether the overflow popup starts open (uncontrolled). |
onOpenChange | (open: boolean, details: AvatarGroupOpenChangeDetails) => void | No | Called when the overflow popup asks to open or close, with the reason: | |
ref | React.Ref<HTMLDivElement> | No | Ref to the root | |
motion | MotionSlot | null | No | the fade and slide above | The overflow popup's motion. By default it fades in and slides 4px away from the overflow button, on the side it opened on, over 200 ms with a decelerating curve, and fades out and slides back over 100 ms with an accelerating curve (focus has moved back to the button by then); under reduced motion it appears and disappears at once. |
slotProps | { item?: SlotPart<'span'>; pie?: SlotPart<'span'>; surface?: SlotPart<'div'>; list?: SlotPart<'ul'>; listItem?: SlotPart<'li'> } | No | Props for the elements the group draws, by part, merged into each part's own: your classes after the part's (yours win a conflict), your styles over its styles, your attributes and handlers added (yours run first), your ref attached. Every attribute the group sets on a part is locked. A part takes no The wrappers, the pie and the list parts hold the members, which may be links: each locks, unset, |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
itempiesurfacelistlistItemAvatarGroup.ItemAvatarGroup.Popover
Stable class names
| Part | Class |
|---|---|
root | wave-avatar-group |
item | wave-avatar-group__item |
overflowButton | wave-avatar-group__overflow-button |
pie | wave-avatar-group__pie |
surface | wave-avatar-group__surface |
list | wave-avatar-group__list |
listItem | wave-avatar-group__list-item |