Skip to content

fix(Avatar): prevent unexpected sizing collapse in Button leadingVisual and flex layouts (#7974) - #8645

Open
Rustaman1280 wants to merge 1 commit into
primer:mainfrom
Rustaman1280:fix/avatar-button-sizing
Open

Rustaman1280 wants to merge 1 commit into
primer:mainfrom
Rustaman1280:fix/avatar-button-sizing

Conversation

@Rustaman1280

Copy link
Copy Markdown

Closes #7974

Summary

When an Avatar component is passed into the leadingVisual slot of a Button (or inside certain CSS grid / flex containers), global stylesheets specifying img { max-width: 100% } can cause the intrinsic width calculation of min-content grid areas to resolve unexpectedly to zero or collapse the avatar.

As diagnosed in #7974, adding min-width alongside width (and flex-shrink: 0) guarantees the Avatar always retains its intended visual dimensions across both standard and responsive size variants.

Changes

  • packages/react/src/Avatar/Avatar.module.css:
    • Added min-width: var(--avatarSize-regular); and flex-shrink: 0; to :where(.Avatar).
    • Added matching min-width properties to the --viewportRange-narrow, --viewportRange-regular, and --viewportRange-wide responsive query blocks.
  • packages/react/src/Button/tests/Button.test.tsx:
    • Added regression test verifying Avatar rendered inside Button leadingVisual slot maintains expected dimensions.
  • .changeset/avatar-button-sizing.md:
    • Added patch changeset.

Verification

  • npm run lint:css: Passed with zero warnings.
  • npx vitest run packages/react/src/Avatar/Avatar.test.tsx: 6/6 tests passed.
  • npx vitest run packages/react/src/Button/__tests__/Button.test.tsx: 60/60 tests passed.

…ng collapse (primer#7974)

- Add min-width and flex-shrink: 0 to :where(.Avatar)
- Add min-width to responsive avatar query styles
- Add regression test rendering Avatar in Button leadingVisual slot
- Add changeset for patch release

Signed-off-by: crustdev <dev@crusts.dev>
@Rustaman1280
Rustaman1280 requested a review from a team as a code owner October 31, 2026 08:23
@changeset-bot

changeset-bot Bot commented Oct 31, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a56c8ff

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch was successfully deployed

1 active deployment
github-pages — a56c8ffb Deployed Oct 31, 2026 by Rustaman1280 via deploy-preview #30288
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avatar in Button leadingVisual slot does not properly size img due to conflicting styles

1 participant