Skip to content

Avatar: add min-width to prevent collapse in min-content containers#8121

Draft
adierkens wants to merge 1 commit into
mainfrom
adierkens-avatar-min-width-button-slot
Draft

Avatar: add min-width to prevent collapse in min-content containers#8121
adierkens wants to merge 1 commit into
mainfrom
adierkens-avatar-min-width-button-slot

Conversation

@adierkens

Copy link
Copy Markdown
Contributor

Closes #7974

Passing an Avatar into the Button leadingVisual slot rendered the image at the wrong width (collapsed to 0). The cause is a collision between the global img { max-width: 100% } rule and Avatar's less-specific width: var(--avatarSize-regular). Because Button sizes the leadingVisual grid area with min-content, max-width can resolve to 0 and the image collapses.

This adds a matching min-width alongside every width declaration in Avatar.module.css (base regular + responsive narrow/regular/wide; the [data-square] variant inherits the base). min-width only sets a floor, so rendered size in normal usage is unchanged — the avatar simply can no longer be shrunk below its intended size by an ancestor's min-content sizing or a global img max-width rule.

Changelog

New

  • Added a LeadingVisualAvatar Button dev story (Button + Avatar leadingVisual across variants/sizes) as a visual-regression anchor.

Changed

  • Avatar now sets min-width matching its width for all size variants, preventing the image from collapsing inside min-content containers such as the Button leadingVisual slot.

Removed

  • N/A

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Open the Components/Button/Dev → Leading Visual Avatar story in Storybook and confirm the avatar renders at its intended size (20px default, 16px small, 24px large) rather than collapsing.

Verified locally: avatars measure 20/16/24px in-browser. A counterfactual (forcing min-width: 0 + max-width: 100% in the min-content track) collapses the avatar to 0px, confirming min-width is what resolves the bug. Existing Avatar unit tests (6/6) and the Storybook smoke test (313/313, including the new story) pass; tsc --noEmit, stylelint, and eslint are clean.

Merge checklist

Passing an Avatar into the Button leadingVisual slot collapsed the image
because the global `img { max-width: 100% }` rule resolves against the
`min-content` grid track. Add a matching `min-width` alongside every
`width` declaration (base regular + responsive narrow/regular/wide) so the
avatar cannot be shrunk below its intended size.

Also adds a Button + Avatar leadingVisual dev story as a VRT anchor.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1a0bd43

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

@github-actions github-actions Bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. If this doesn't work, you can also use the original workflow here. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm

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