Repository navigation
fix(Badge): a long label no longer escapes its container - #5558
Conversation
`Badge` set `white-space: nowrap` with nothing to clip it — the one pairing that neither wraps nor truncates. A label wider than the space available rendered outside the badge's container and over whatever sat beside it. Measured in Chromium, `label="Awaiting security review"` in a 100px column: 163px wide, 63px of it outside the column. In a fixed-layout table cell it painted 64px over the text in the next cell. `maxWidth: 100%` clamps it and `minWidth: 0` lets it actually shrink — as a flex item the automatic minimum size would otherwise hold the badge at its full text width and undo the clamp. The ellipsis goes on a new inner label span rather than the badge itself, because `text-overflow` needs a block container and taking the root off `inline-flex` to get one would cost the icon its centring; with an icon, the icon holds its place and the label gives way. A badge that already fits is untouched: measured before and after, one with room to spare is 53px either way. Only the cases that were already overflowing change. No hooks, so `Badge` stays one of the few core components that renders on the server. A tooltip carrying the full text needs runtime measurement and would make it a client component — that is a separate change with its own trade-off, and this fix stands without it. No unit test for the clamp itself: jsdom has no layout, so the only thing it could assert is the declaration. The Chromium measurements are the evidence.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
A worktree-local symlink to a sibling install got committed with the change, and `pnpm install --frozen-lockfile` then fails on it — which is why every job on this PR went red before reaching any build step. Nothing to do with the change itself.
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsBadge (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Visual Regression70 added · 0 removed. View the report To accept these exact frames: Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
rubyycheung
left a comment
There was a problem hiding this comment.
The containment behavior looks right: the badge stays within its available width, the icon remains visible, and labels that fit are unchanged.
However, truncating the label hides meaningful status text with no way for sighted users to recover it. The new story even says to hover for the full text, but Badge adds neither a tooltip nor a title, so hovering currently reveals nothing.
Please add an accessible way to expose the complete label when it is truncated—ideally a tooltip available on hover and keyboard focus, with an explicit touch-device alternative. A native title would be a minimum fallback, but silent truncation should not ship on its own.
cixzhang
left a comment
There was a problem hiding this comment.
Thanks, this fixes the spill. I agree with Ruby’s hold though: the status is now clipped, but the rendered badge has no title, tooltip, or other path for a sighted user to recover the full label. Can you add a server-safe full-label fallback for string/number labels and keep the richer only-when-truncated tooltip as its own PR if it needs measurement?
[Reviewed by Robohands]
Truncation without a way back to the full text is what Ruby and cixzhang held the PR on: the label is clipped, and the tail is simply gone. A string or number label is now also set as the badge's `title`. That is the half of the answer that costs nothing — no measurement, no hook — so `Badge` renders identically on the server and stays usable in a server component. It follows the shape `BaseTable` already uses for a truncated header cell: string content only, and only when there is something to show. A rich label is left alone, because flattening a subtree to a string renders a guess. Two gaps stay open, both needing runtime measurement: the `title` is set whether or not the label actually fits, and a native `title` answers hover but not keyboard focus and not touch. The measured, only-when-cut tooltip is a client component and belongs in its own PR, as cixzhang asked. The `LongLabels` story previously promised the full text on hover while nothing supplied it — Ruby's catch. Its comment is now accurate about both what works and what does not.
The changeset, the story and the component comment all said the focus/touch-reachable tooltip was "tracked separately" without saying where. It is #5585.
|
Both holds addressed, in the shape @cixzhang scoped: a server-safe fallback here, the measured tooltip as its own thing. What's in now ( const labelTitle =
typeof label === 'number'
? String(label)
: typeof label === 'string' && label.length > 0
? label
: undefined;That's the same shape Four tests cover it: string → @rubyycheung — your catch on the story was right, and it was worse than a missing tooltip. The What this does not close, and I'd rather say it plainly than let
Both are in #5585, along with the reason they're not here: doing it properly needs |
|
@rubyycheung re-requesting — your hold was the one this head answers. The full text now rides in the badge's Being straight about what it does not do, since you asked for more than the minimum: The story comment you caught was the worse half of this and is fixed: it no longer promises something nothing supplied. |
cixzhang
left a comment
There was a problem hiding this comment.
Re-approving after the mechanical main refresh; the reviewed change is unchanged.\n\n[Reviewed by Robohands]
cixzhang
left a comment
There was a problem hiding this comment.
Re-approving after the mechanical main refresh; the reviewed change is unchanged.
[Reviewed by Robohands]
cixzhang
left a comment
There was a problem hiding this comment.
Re-approving after the mechanical main refresh; the reviewed change is unchanged.
[Reviewed by Robohands]
|
/accept-visual 33045929788/1 These 70 frames add Badge coverage; no existing pixels changed, and sensor-backed review verified layout containment plus the intended full-label fallback. |
|
Visual acceptance refused: only a repository maintainer may accept stable visual changes. |
|
/accept-visual |
|
Visual acceptance refused: copy the exact |
|
/accept-visual 33045929788/1 These 70 frames add Badge coverage; no existing pixels changed, and sensor-backed review verified layout containment plus the intended full-label fallback. |
|
Visual acceptance refused: only a repository maintainer may accept stable visual changes. |
|
/accept-visual 33045929788/1 These 70 frames add Badge coverage; no existing pixels changed, and sensor-backed review verified layout containment plus the intended full-label fallback. |
|
Visual changes accepted for |



Summary
Badgesetswhite-space: nowrapwith nothing to clip it — the one pairing that neither wraps nor truncates. A label wider than the space available doesn't ellipsize, it renders outside the badge's container, over whatever sits beside it.plus
overflow: hidden; text-overflow: ellipsis; min-width: 0on a new inner label span.Rubric B10 — "long text truncates or wraps with no layout breakage" — severity FIX.
Measured in Chromium
label="Active"That last row is the one that matters for risk: a badge with room to spare is identical before and after. The clamp only ever changes a case that was already overflowing.
Why the inner span
text-overflowneeds a block container. The badge root isinline-flex, and taking it off that to get one would cost the icon its vertical centring — so the ellipsis goes on the label instead, and with an icon the icon holds its place while the label gives way.minWidth: 0is not decoration. As a flex item the badge's automatic minimum size is its max-content width, which holds it at full text width and undoesmaxWidth: 100%entirely; the label span needs the same for the same reason.What is deliberately not here
A tooltip carrying the full text. Only-when-truncated needs a
scrollWidth > offsetWidthmeasurement, which means hooks — andBadgeis currently one of the ~24 files inpackages/core/srcwith no'use client'. [[RSC Compatibility]] namesBadgespecifically among the components that should become server-renderable, so quietly making it a client component inside a defect fix is the wrong trade to make silently. It is a separate PR with its own case to argue, and this fix stands without it.Test plan
pnpm build,verify-exports,check:repo,lint:strict, core + storybook + CLI-strict typechecks — clean. Badge: 8/8 existing tests pass unchanged.pnpm a11y:audit -- --components Badge: 0 new violations. (It also reports 2color-contrastbaseline entries as resolved — I checked, those report identically onmain, so they are not this PR's doing.)Where this came from
An engineer asked whether Badge had a max width, having hit exactly this in a hover card. The workaround in the wild is per-call-site:
Structurally that is this fix, which is a decent signal it belongs in the component — one wrapper knows to do it, the next person putting a Badge in a table cell won't.
@freddymeta