Skip to content

fix(Avatar): AvatarGroupOverflow grows to a pill for long +N counts (#4167) - #4196

Merged
cixzhang merged 1 commit into
mainfrom
fix/avatar-group-overflow-pill
Jul 22, 2026
Merged

cixzhang merged 1 commit into
mainfrom
fix/avatar-group-overflow-pill

Conversation

@cixzhang

Copy link
Copy Markdown
Contributor

What

AvatarGroupOverflow grows into a pill for long +N counts so the number never clips.

Previously the indicator was a fixed-size circle (width: size; height: size). With larger counts (e.g. +4912) the text was wider than the circle and clipped/crowded the edges.

Now the indicator:

  • pins height to the avatar size (unchanged),
  • enforces a minimum width equal to the avatar size (minus the inline padding), and
  • adds horizontal padding via a spacing token.

Short counts (+5) stay a perfect circle; longer counts grow horizontally into a stadium/pill. The full radius on a wider-than-tall box yields the pill shape automatically — no new public prop.

Why

Hardening/style fix: the component already claims to support arbitrary counts, but the fixed circle broke the "long content" overflow case for multi-digit numbers.

Testing

  • pnpm build — pass
  • pnpm test — pass (added a test asserting the full +4912 text renders and its accessible label is intact)
  • pnpm lint — pass
  • Added a CircleToPill Storybook story showing +5 (circle) next to +4912 (pill) so the difference is visible.
  • The clickable (button) variant preserves the inline padding — its padding reset was narrowed from the padding shorthand to paddingBlock: 0 so the pill's horizontal breathing room survives.

Closes #4167

@vercel

vercel Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
astryx Ready Ready Preview, Comment Jul 22, 2026 12:38pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 22, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Jul 22, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

Quick Self-Review (refactor/update checklist)

  1. Icons from registry — N/A; no icons touched.
  2. themeProps present — Unchanged. themeProps('avatar-group-overflow') still applied via mergeProps on both the <span> and <button> roots.
  3. No wrapper divs — No new DOM. Handlers/refs remain on the interactive <button> / <span> itself.
  4. No CSS shorthands — Replaced the padding: 0 shorthand on the button variant with explicit paddingBlock: 0 (so the base paddingInline survives). Added paddingInline (logical, not a shorthand). No flex shorthand introduced.
  5. ARIA still correct — No primitive changes. aria-label={${count} more} unchanged; added a test asserting getByLabelText('4912 more').
  6. Tests pass locally — AvatarGroup.test.tsx 17/17 pass in isolation; full pnpm test green (368 files / 7350 tests).
  7. Sandbox/stories updated — Added a CircleToPill story (+5 circle vs +4912 pill) and refreshed the EN/ZH doc best-practice copy.
  8. Popover background — N/A.

Design notes

  • No new public prop. The behavior is derived purely from content width: minWidth = size − 2·paddingInline, height = size, borderRadius: --radius-full. Short counts stay a circle (min width + padding == size); wide counts grow into a stadium/pill.
  • Spacing token, not raw px. Horizontal padding uses spacingVars['--spacing-2']. The OVERFLOW_PADDING_INLINE = 8 constant only mirrors that token's value for the minWidth subtraction (kept in a comment for traceability).
  • content-box preserved, so the circle diameter equals the avatar size for short counts.
  • StyleX-verified: paddingInline and minWidth are supported per internal/stylex-capabilities/CAPABILITIES.md.

@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

📚 Storybook Preview

View Storybook for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

🧪 Sandbox Preview

View Sandbox for this PR
GitHub Pages may take up to a minute to hydrate after deploy.

Modified Components

AvatarGroup · View in Storybook
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 225 -
Complexity N/A Medium (10) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.7KB 0B

Accessibility Audit

Status: 1 accessibility violation(s) found — 1 serious.

AvatarGroup - 1 issue(s)
  • 🟠 serious: Ensure the contrast between foreground and background colors meets WCAG 2 AA minimum contrast ratio thresholds
    • Rule: color-contrast · Affects 1/13 stories · Learn more
    • WCAG: 1.4.3 (Level AA)

Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

// horizontally into a stadium/pill for wide content (`+4912`) without
// clipping. The min width subtracts the inline padding (applied on both
// sides via `boxSizing: content-box`) so the circle diameter equals `s`.
minWidth: Math.max(0, s - OVERFLOW_PADDING_INLINE * 2),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tokens not hardcoded values

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed. The OVERFLOW_PADDING_INLINE = 8 constant (a raw mirror of the --spacing-2 token) is gone entirely. paddingInline now reads spacingVars['--spacing-2'] directly, and thanks to the border-box switch there's no JS-side arithmetic that needed the token's numeric value.

// the box stays a perfect circle for short counts (`+5`) and grows
// horizontally into a stadium/pill for wide content (`+4912`) without
// clipping. The min width subtracts the inline padding (applied on both
// sides via `boxSizing: content-box`) so the circle diameter equals `s`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we can clean this up by using border box so simplify this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — switched to boxSizing: 'border-box'. With border-box the inline padding lives inside the box, so minWidth can be set to the size directly (grown by the 2px border to match the sibling avatars' rendered size). Short counts stay a perfect circle at the avatar size; longer content pushes past the min width and grows into a pill. No more subtraction arithmetic.

The overflow indicator was a fixed-size circle, so wide counts (e.g. +4912)
clipped/crowded the edges. Switch to border-box and enforce a minimum width
equal to the avatar size: short counts stay a circle, and the inline padding
(inside the box) lets longer counts grow into a stadium/pill so the number
always fits.

Closes #4167
@cixzhang
cixzhang force-pushed the fix/avatar-group-overflow-pill branch from e89a93d to 7a28722 Compare July 22, 2026 12:34
@cixzhang

Copy link
Copy Markdown
Contributor Author

Review feedback addressed (force-pushed)

Both inline comments resolve together via the border-box switch:

  • border-box (L117) — boxSizing is now border-box. The inline padding and the 2px border are included in the box, so the size can be set directly instead of subtracting padding from a content-box width.
  • No hardcoded token value (L118) — the OVERFLOW_PADDING_INLINE = 8 constant is deleted. paddingInline uses spacingVars['--spacing-2'] directly; with border-box there's no arithmetic that needed the token's numeric value.

Sizing now reads: minWidth: size + 2·BORDER_WIDTH, height: size + 2·BORDER_WIDTH (the border is added to match the sibling avatars' rendered size, since their ring uses content-box + a 2px border). Short counts (+5) render a perfect circle at the avatar size; longer counts (+4912) push past the min width and grow into a stadium/pill. Verified via the CircleToPill story and the unit test.

Re-ran gates: pnpm -F @astryxdesign/core build ✓, pnpm vitest run packages/core/src/AvatarGroup ✓ (17/17), lint ✓.

Accessibility finding — pre-existing, not introduced by this PR

The reported color-contrast violation (1/13 stories, serious) is on the overflow indicator's +N text: --color-text-secondary on the --color-neutral tint. In the audited neutral theme / light mode this resolves to #737373 on ~#F0F0F0 ≈ 4.16:1, just under the 4.5:1 AA threshold for normal text.

This color pairing is part of the component's existing styling and is unchanged by this PR — the same color: --color-text-secondary over the --color-neutral background exists on main (where 8 overflow stories already used it). This PR only changes box-sizing / width / padding, not any color. The failing-story count did not increase: main had 12 stories with 1 failing; this PR adds CircleToPill (13 total) and it still reports 1 failing.

Fixing the contrast would mean adjusting the --color-text-secondary token or the indicator's text color — a token/theme-level change affecting many components — so I've kept it out of scope here and am flagging it as pre-existing a11y debt worth a separate issue.

github-actions Bot added a commit that referenced this pull request Jul 22, 2026
@cixzhang
cixzhang marked this pull request as ready for review July 22, 2026 22:34
@cixzhang
cixzhang merged commit 1055df2 into main Jul 22, 2026
26 checks passed
nynexman4464 added a commit that referenced this pull request Jul 22, 2026
…cale rename (#4221)

PR #4196 added a LongCount story with size="medium", but PR #4140 renamed
AvatarSize to the abbreviated Icon scale ("md" instead of "medium"). The
land order left a stale value that broke storybook typecheck on main.
@github-actions
github-actions Bot deleted the fix/avatar-group-overflow-pill branch July 23, 2026 06:55

This branch was successfully deployed

1 active deployment
Preview — 7a28722e Deployed Jul 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AvatarGroupOverflow: grow to a pill for long counts so "+N" text doesn't clip

1 participant