chore(Breadcrumbs): add story reproducing false collapse on content-sized container - #2732
Open
ykamendrovskiy wants to merge 1 commit into
Open
Conversation
Contributor
Reviewer's GuideScopes a layout-measurement bug fix to Breadcrumbs by measuring each breadcrumb item in the same box model as the container (including horizontal margins), and adds a visual regression test ensuring Breadcrumbs do not collapse when they fit within a flex row with extra space. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- When summing horizontal margins in
getChildWidth, consider defensively normalizingmarginLeft/marginRight(e.g., treatingNaNor non-pixel values as0) so that unexpected computed styles (likeauto) don’t propagateNaNand break the collapse logic.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When summing horizontal margins in `getChildWidth`, consider defensively normalizing `marginLeft`/`marginRight` (e.g., treating `NaN` or non-pixel values as `0`) so that unexpected computed styles (like `auto`) don’t propagate `NaN` and break the collapse logic.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
ykamendrovskiy
force-pushed
the
fix/breadcrumbs-false-collapse
branch
from
July 7, 2026 14:19
a263a92 to
764ff01
Compare
…ized container Adds a Storybook story showing Breadcrumbs collapse into the "…" menu even though nothing overflows, whenever the <ol> is sized to its content (a flex child without `flex: 1`). See the PR description for the root cause and a proposed fix.
ykamendrovskiy
force-pushed
the
fix/breadcrumbs-false-collapse
branch
from
July 7, 2026 14:24
764ff01 to
4bb613a
Compare
Contributor
|
Preview is ready. |
Contributor
|
🎭 Component Tests Report is ready. |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Breadcrumbswith a few short items collapses part of them into the…popover immediately — even when there is plenty of free space and nothing overflows. It happens whenever the breadcrumbs'<ol>is sized to its content (shrink-wrap), e.g. when<Breadcrumbs>sits in a flex row withoutflex: 1— a very common page-header layout.This PR adds a Storybook story reproducing the issue:
Components/Navigation/Breadcrumbs→FalseCollapseOnContentWidth. No fix is included — the proposed solution is described below for your consideration.Root cause
useCollapseChildrencompares two measurements taken in different box models:container.getBoundingClientRect().width, which on the flex<ol>equals the sum of the items' margin-boxes;getBoundingClientRect().width, i.e. the border-box, without margins.The current item (
.g-breadcrumbs__item_current) carries a negative inset margin (margin: -2px, paired withpadding: 2pxto inset the focus ring). So on a content-sized container the summed item widths exceed the container width by that margin,availableWidthbecomes-4px < 0, and the list collapses. It is deterministic (measured Δ = exactly −4px), not a sub-pixel or real-overflow effect.Proposed solution (not applied)
Measure items in the same box model as the container by including their horizontal margins in
Breadcrumbs'getChildWidth:getChildWidth: (child) => { - const width = child.getBoundingClientRect().width; + const {marginLeft, marginRight} = window.getComputedStyle(child); + const width = + child.getBoundingClientRect().width + parseFloat(marginLeft) + parseFloat(marginRight); const maxWidth = child.dataset.current ? 200 : Infinity; return Math.min(maxWidth, width); },With this change the summed item widths equal the container width (
availableWidth === 0), so the list no longer collapses when it fits, while real overflow still collapses as before. I verified it locally against the story above.Why scoped to
Breadcrumbsand not the hook. The mismatch itself is more general —useCollapseChildrenmeasures the container in its margin-box but each child in its border-box, so any consumer whose children carry margins can hit it. The other consumer,Tabs, already accounts for its item margins by passing them as the hook'sgap, so making the hook's default measurement margin-aware would double-count them forTabs. Hence the local fix. If you'd rather solve it once at the hook, that path would need to reconcile the two (e.g. document the box-model contract the hook expects, or make margin-vs-gaphandling explicit).Happy to open a follow-up with the fix + a regression test if you'd prefer.