Skip to content

AvatarGroup

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

NameTypeRequiredDefaultDescription
maxnumberNo

Maximum number of avatars to display. The others are replaced by an overflow button that lists their names. 0 or a negative value shows only the overflow button, a fraction is rounded down, and NaN shows every member (as without max). The members of a Fragment count one by one. A pie shows at most three.

size'extra-small' | 'small' | 'medium' | 'large' | 'extra-large' | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 48 | 56 | 64 | 72 | 96 | 120 | 128No'medium' ('large' in a `pie`)

Size of the avatars. It reaches the members that set no size of their own, and the overflow button.

layout'stack' | 'spread' | 'pie'No'stack'

How the members are laid out: stack overlaps them, spread puts them side by side, pie draws up to three of them as the wedges of one circle (the group's name is then the only name).

overflowIndicator'count' | 'icon'No'count'

What the overflow button shows: the number of hidden members (+3, capped at 99+), or an icon.

overflowLabelstring | ((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.

unnamedMemberLabelstringNo'Unnamed member'

Text listed in the overflow popup for a hidden member that has no accessible name (an Avatar without name, aria-label, aria-labelledby or image alt, or blank text). Localise it here; better still, give every member a name (a development warning asks for it).

openbooleanNo

Whether the overflow popup is open (controlled).

defaultOpenbooleanNofalse

Whether the overflow popup starts open (uncontrolled).

onOpenChange(open: boolean, details: AvatarGroupOpenChangeDetails) => voidNo

Called when the overflow popup asks to open or close, with the reason: trigger (the button), escape, outside-press or focus-outside, and the event (details.event). WaveUI always passes details.

refReact.Ref<HTMLDivElement>No

Ref to the root <div>.

motionMotionSlot | nullNothe 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. null turns the motion off (the popup still renders its data-presence phases, which then end at once); a class string or { className } replaces the default classes with yours (see MotionSlot), also under a WaveProvider with motion="none", which otherwise turns the default off. Fluent's popup surfaceMotion.

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 children (the group draws their content); the members and the overflow button take their own props (an AvatarGroup.Popover you write is the button).

The wrappers, the pie and the list parts hold the members, which may be links: each locks, unset, role, tabIndex, the roving container marker data-roving-container (it would take a member out of the arrow-key order of a toolbar around the group) and hidden, inert and aria-hidden. The popup's parts reach the built-in overflow and an AvatarGroup.Popover you write alike, through the group's context: keep the surface, list and listItem objects stable (a constant or a memoised value) where the members are memoised, since a new object renders every member again.

Any other prop is passed to the element it renders (HTMLDivElement).

Parts

  • item
  • pie
  • surface
  • list
  • listItem
  • AvatarGroup.Item
  • AvatarGroup.Popover

Stable class names

PartClass
rootwave-avatar-group
itemwave-avatar-group__item
overflowButtonwave-avatar-group__overflow-button
piewave-avatar-group__pie
surfacewave-avatar-group__surface
listwave-avatar-group__list
listItemwave-avatar-group__list-item