Skip to content

fix(Badge): a badge is as wide as its label, and never stretches in a Grid cell or a VStack - #12053

Merged
josephfarina merged 2 commits into
mainfrom
josephfarina/badge-fit-content
Nov 16, 2026
Merged

josephfarina merged 2 commits into
mainfrom
josephfarina/badge-fit-content

Conversation

@josephfarina

Copy link
Copy Markdown
Contributor

User impact

A Badge placed on its own in a Grid cell or a VStack stretched into a bar across the cell or the stack. A grid cell and the cross axis of a vertical stack stretch a child whose width is auto, which is the default for both, and Badge's root left its width auto. Pages built from templates hit it on their own: a status badge under a heading in a VStack became a full-width colored bar, and a badge in a card grid filled its whole cell.

Problem and solution fit

  1. Why it occurs: Badge's root is inline-flex with width: auto. As a grid item or a flex item on the cross axis, an auto width stretches to the cell or the stack.
  2. Why it harms the task: a badge reads as a short, compact label; a bar across the page reads as a banner or a divider, and draws far more attention than the status it carries.
  3. Why that matters: badges are used for status in every list, card and header; the default layouts (Grid, VStack) should not change what a badge looks like.

width: fit-content on the root keeps the badge as wide as its label in a grid cell and a stack. In a flex row it still shrinks: its flex basis follows this width, and the existing min-width: 0 and max-width: 100% let it go below its content, so a crowded row still cuts the label with an ellipsis inside the badge.

Expected behavior and authority

component:Badge FR3 (amended in this PR, one describing clause): the root is as wide as its content, so it does not stretch to fill a grid cell or the cross axis of a stack; it is capped at the inline size of its container and may shrink below its content size, with the label cut by an ellipsis. FR1 already describes the badge as a compact one-line pill.

Smallest restoration

One style declaration (width: 'fit-content') on Badge's root, with a comment saying why; the Badge record's FR3 and summary row describe it; the label prop description says it. No new prop, default or theme target.

Evidence

  • Reproduction before the change: the new Core/Badge In layouts story at Badge's current source: badges in a two-column Grid are as wide as their cells, and a badge in a VStack is as wide as the stack (the new browser spec fails on both cases).
  • Result after the change: in the Grid each badge is its label's width and at least 40 px narrower than the width the cell would stretch it to; in the VStack the badge is under half the stack's width; neither label is cut.
  • Representative unchanged path: in a crowded HStack the badge still shrinks, cuts its label with an ellipsis and stays inside the row; the existing Larger text browser spec (neutral and Butter themes: theme height, growing with larger text, crowded row, narrow cell) passes unchanged.
  • Regression test: BadgeInLayouts.a11y.chromium.spec.ts measures each badge as it is and with width: auto in the Grid, VStack and HStack cases. Without the change the Grid and VStack cases fail; with it all three pass.

Scope

Components: Badge

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Writing rubric results

R1 narration: none; the FR3 clause and the summary row state what the badge does.
R2 research: none in the record.
R3 evidence: the new verification row cites the browser spec and the story, not a change.
R4 rejected alternatives: none added.
R5 change references: none.
R6 open questions: OQ1 is unchanged and still unanswered.
R7 project status: none.

Testing

  • pnpm storybook:build, then pnpm exec playwright test BadgeInLayouts BadgeLargerText (Chromium): 13 passed; with Badge's current source, the two new Grid and VStack cases fail.
  • pnpm exec vitest run --project ui packages/core/src/Badge packages/core/src/Grid packages/core/src/Stack (106 tests)
  • pnpm check:knowledge; node scripts/check-changesets.mjs; Prettier and ESLint on the changed files.

@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 16, 2026 10:24am UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@astracat-bot

astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 16, 2026, 10:34 AM UTC

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Nov 16, 2026
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 1c2fc4b

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 08da884

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Badge · Storybook 4.4 kB (+14 B) · 4.0 kB CSS (+16 B) 232 (+1) ✓ · ✓ · —
ChatTokenizedText 7.6 kB (+14 B) · 4.0 kB CSS (+16 B) — — · — · —
ChatComposerDrawer 18.2 kB (+12 B) · 4.7 kB CSS (+14 B) — — · — · —
9 more components
Component Size LoC Visual · A11y · RTL
MultiSelector 101.5 kB (+13 B) · 17.7 kB CSS (+12 B) — — · — · —
ChatToolCalls 31.6 kB (+9 B) · 8.4 kB CSS (+14 B) — — · — · —
ChatComposer 84.6 kB (+7 B) · 12.9 kB CSS (+12 B) — — · — · —
ChatComposerInput 82.3 kB (+8 B) · 12.1 kB CSS (+10 B) — — · — · —
ChatComposerTokenElement 82.3 kB (+8 B) · 12.1 kB CSS (+10 B) — — · — · —
lab/TabBarMoreList 102.0 kB (+14 B) · 1.8 kB CSS (0) — — · — · —
lab/CommentThread 363.1 kB (+8 B) · 2.4 kB CSS (0) — — · — · —
lab/Comments 370.0 kB (+7 B) · 2.5 kB CSS (0) — — · — · —
lab/CommentComposer 173.7 kB (+6 B) · 1.9 kB CSS (0) — — · — · —

Package size: @astryxdesign/core 7.61 MB packed (+140 B); no new dependencies.

Touched components checked; for the full suites, add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes requested: the fix works, but the Badge record does not yet state its compatibility effect.

  • The Badge record's Compatibility class (docs/specs/components/Badge/Badge.spec.md, lines 56-58) and its Compatibility/readiness row (line 41) still describe only the earlier dir="ltr" change, so add that FR3 is a visible, non-breaking layout correction (a badge alone in a grid cell or on a stack's cross axis keeps its content width), as other component records do.

The new browser spec fails on main for the Grid and VStack cases and passes with this change, and the crowded-row and Larger text checks are unchanged. One optional suggestion: the new comment in Badge.tsx (lines 51-55) can be shorter and in the present tense, as noted inline.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim, title: a badge is as wide as its label and never stretches in a Grid cell or a VStack. Verified: the new spec fails on main and passes here.
  • Claim, changeset: a lone badge in a Grid cell or a VStack no longer stretches, and in a crowded HStack it still shrinks with an ellipsis. Verified: Grid badges go from 156 px to 62.6 and 51.1 px, the VStack badge from 320 px to 56.1 px, and the crowded-row badge stays 52 px with its label cut on both sides.
  • Claim, cause: the root is inline-flex with an auto width, which a Grid cell and a VStack's cross axis stretch. Verified: Grid and Stack set no alignment by default.
  • Claim, a flex row still shrinks the badge through its flex basis and the existing min and max widths. Verified by the crowded-row case.
  • Claim, the record already describes the badge as a compact one-line pill. Verified in substance: the wording is the record's Design relationships row for the root, which cites FR1.
  • Claim, one style declaration with FR3, the summary row and the label description updated, and no new prop, default or theme target. Verified: the built API surface is unchanged.
  • Claim, the evidence: failures before the change, measurements after it (more than 40 px narrower in the Grid, under half the stack), and an unchanged crowded row and Larger text spec. Verified by running the specs on both sides.
  • Claim, pages built from templates hit the bug. Not checkable in the repository: no shipped page template puts a lone badge in a stretching stack or grid.
  • Claim, testing: 13 Playwright and 106 Vitest tests pass, and the knowledge and changeset checks pass. Verified.
  • Claim, writing rubric results are none and the open question is unchanged. Verified.
  • Claim, scope checklist: one defect, no tagalong, nothing hidden under the fix label, and no internal context. Verified: one style change, an unchanged API surface, and no internal references in the added text.
  • File .changeset/badge-fits-its-label.md: clear.
  • File apps/storybook/stories/Badge.stories.tsx: clear.
  • File docs/specs/components/Badge/Badge.spec.md: compatibility statement finding.
  • File packages/core/src/Badge/Badge.doc.mjs: clear.
  • File packages/core/src/Badge/Badge.tsx: clear, with one optional comment suggestion.
  • File packages/core/src/Badge/__tests__/BadgeInLayouts.a11y.chromium.spec.ts: clear.

Automated review (maintainer link)

Comment thread packages/core/src/Badge/Badge.tsx Resolved
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec 08da884

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved pending CI: the CI run on this head was cancelled because CI was full, so its build and test jobs have no result yet; re-running CI is the next step. The Badge record's compatibility notes now name the FR3 layout correction, which resolves the earlier change request, and the new browser spec fails without this change for the Grid and VStack cases and passes with it.

One optional suggestion: the new comment in Badge.tsx (lines 51-54) can drop "lets it go under" and the sentence that restates fit-content, as noted inline.

Claims and files checked

Review mode: full; reason: spec-record

  • Claim, title: a badge is as wide as its label and never stretches in a Grid cell or a VStack. Verified: the new spec fails on the base and passes here.
  • Claim, changeset: a lone badge in a Grid cell or a VStack no longer stretches, and in a crowded HStack it still shrinks with an ellipsis. Verified: Grid badges go from 156 px to 62.6 and 51.1 px, the VStack badge from 320 px to 56.1 px, and the crowded-row badge stays 52 px with its label cut on both sides.
  • Claim, changeset: a patch release of the core package. Verified: no public API changes, and the changeset check passes.
  • Claim, cause: the root is inline-flex with an auto width, which a Grid cell and a VStack's cross axis stretch. Verified: Grid and Stack set no alignment by default.
  • Claim, pages built from templates hit the bug. Verified in mechanism: any lone badge in a default VStack or Grid stretched on the base; no shipped page template places one that way.
  • Claim, a flex row still shrinks the badge through its flex basis and the existing minimum and maximum widths. Verified by the crowded-row case.
  • Claim, FR3 is amended in one describing clause and the record already calls the badge a compact one-line pill. Verified: the FR3 clause is the only requirement change, and the pill wording is the record's design row for the root.
  • Claim, one style declaration with a comment, FR3, the summary row and the label description updated, and no new prop, default or theme target. Verified: the built API surface is unchanged; the follow-up commit also updates the record's compatibility notes.
  • Claim, the evidence: failures before the change, measurements after it (more than 40 px narrower in the Grid, under half the stack), and an unchanged crowded row and Larger text spec. Verified by running the specs on both sides.
  • Claim, testing: 13 Playwright and 106 Vitest tests pass, and the knowledge and changeset checks pass. Verified.
  • Claim, testing: Prettier and ESLint on the changed files. Verified for the TypeScript and Markdown files; the doc file keeps formatting it already had on main, which no check enforces.
  • Claim, writing rubric results are none and the open question is unchanged. Verified.
  • Claim, scope checklist: one defect, no tagalong, nothing hidden under the fix label, and no internal context. Verified.
  • File .changeset/badge-fits-its-label.md: clear.
  • File apps/storybook/stories/Badge.stories.tsx: clear.
  • File docs/specs/components/Badge/Badge.spec.md: clear; the compatibility notes match FR3.
  • File packages/core/src/Badge/Badge.doc.mjs: clear.
  • File packages/core/src/Badge/Badge.tsx: optional comment-style suggestion.
  • File packages/core/src/Badge/__tests__/BadgeInLayouts.a11y.chromium.spec.ts: clear.

Automated review (maintainer link)

Comment on lines +51 to +54
// A badge is as wide as its label. A grid cell and the cross axis of a
// stack stretch a child whose width is `auto`. In a flex row the badge
// still shrinks: its flex basis follows this width, and the minimum below
// lets it go under.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional (comment style): "lets it go under" is vague, and the first sentence restates what fit-content does. A version that keeps only the reason:

// A grid cell and a stack's cross axis stretch an `auto` width. In a flex
// row, the flex basis follows this width, and `minWidth: 0` below lets the
// badge shrink under its content width.

@josephfarina
josephfarina merged commit 5b8aa79 into main Nov 16, 2026
252 of 301 checks passed
@github-actions
github-actions Bot deleted the josephfarina/badge-fit-content branch November 17, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — 08da8844 Deployed Nov 16, 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant