Skip to content

fix(flexpanel): size an inner panel to its content when it is a flex item - #1676

Merged
Kunal22shah merged 4 commits into
mainfrom
dev/ks/flexpanel-row-item-width
Oct 14, 2026
Merged

Kunal22shah merged 4 commits into
mainfrom
dev/ks/flexpanel-row-item-width

Conversation

@Kunal22shah

@Kunal22shah Kunal22shah commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #1675

PR Type

  • Bugfix

What is the current behavior?

A FlexPanel placed directly inside another FlexPanel fills the width it is offered, even when the parent only measures it for its content (flex-basis resolution, or a non-stretch cross axis). In a row it takes the whole line, so its Grow siblings get no width; in a centered column it is full width instead of hugging its content. Details and repro in #1675.

Out of scope: an inner panel behind another panel (StackPanel, Border, Grid) still fills what that panel hands it — the parent-mode signal deliberately does not cross a non-FlexPanel, as When_InnerFlexPanelUnderGridRow_ThenFillsDefiniteSlot already asserts. HorizontalAlignment="Left" on the inner panel remains the opt-out there.

What is the new behavior?

As a flex item, an inner panel's base size is its content, as in CSS. MeasureCore now treats the width axis like the height axis already is: when the parent FlexPanel measures a direct child with AtMost / Undefined width, the child reports its content width instead of the cap. Exactly (stretch, or a resolved grow share) still fills, and HorizontalAlignment != Stretch is still the fit-content opt-in.

The change is the width twin of _parentFlexHeightMode: one more field, set by the parent's measure function on direct FlexPanel children only, with the same invalidation when the mode changes.

New runtime tests:

  • When_InnerFlexPanelIsRowItem_ThenSizedToContentAndGrowSiblingGetsRemainder (with and without Shrink=0) — 80/520 instead of 600/0
  • When_InnerFlexPanelIsGrowingRowItem_ThenFillsItsShare — 500 instead of 515
  • When_InnerFlexPanelInCenteredColumn_ThenSizedToContent — 80 instead of 600
  • When_InnerFlexPanelInStretchColumn_ThenFillsCrossAxis — guard: the default stretch column still fills (600)
  • When_NestedRowsWithGrowSiblings_ThenMeasureCountDoesNotCompound — guard: five nested Grow rows stay at two measures or fewer per level

The first three fail without the fix. doc/controls/FlexPanel.md gains a "Nesting FlexPanels" section: content-sized in a row unless grown, filled in a stretch column, and HorizontalAlignment="Left" when another panel sits in between.

Behaviour change to note in the release: an inner FlexPanel that is not grown, or sits in a column with AlignItems/AlignSelf other than Stretch, now hugs its content instead of spanning the line. Restore the old fill with Grow="1" or AlignSelf="Stretch".

PR Checklist

  • Tested the changes where applicable:
    • Desktop (Windows) — all 37 FlexPanelTests pass in the Material sample app
  • Runtime tests added
  • Backport to servicing/10.0 (FlexPanel shipped there via feat: FlexPanel (backport #1639) #1658) once this is reviewed

…item

- a FlexPanel measured by a parent FlexPanel for content (AtMost/Undefined
  width) no longer fills the offered width; it was taking the whole line and
  leaving its Grow siblings with nothing
- mirrors the existing height-axis handling (_parentFlexHeightMode) for the
  width axis; HorizontalAlignment != Stretch still opts into fit-content
- tests: inner row item sized to content, growing inner item fills its share,
  inner panel in a centered column hugs its content
Copilot AI balanced review requested due to automatic review settings October 14, 2026 16:45

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

- outerFlexWantsContent becomes outerFlexWantsContentHeight beside the width one
- the measure-function comment now says both modes are handed to the child
- inner row item is content-sized with and without Shrink=0
- inner panel in a default stretch column still fills it
- centered inner panel's actual width hugs its content
- nested Grow rows keep each level at two measures or fewer
@Kunal22shah
Kunal22shah requested a review from Xiaoy312 October 14, 2026 17:01
@github-actions

Copy link
Copy Markdown

@Xiaoy312 Xiaoy312 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.

LGTM. Verified locally on Desktop: the three new tests fail on main and pass here, and the rest of FlexPanelTests still passes.

One note on When_NestedRowsWithGrowSiblings_ThenMeasureCountDoesNotCompound: it also passes on main, so it doesn't really guard the new width-mode invalidation. The inner panels don't grow, so their final Exactly width equals the size already measured for the basis. Yoga reuses that cached measurement and never calls the measure function a second time, so the width mode never actually flips. (Height = 100 makes no difference here either: the counts are 1 per level with or without it.)

A variant where each inner panel has Grow="1" (next to a fixed-width sibling, with the root at VerticalAlignment="Top" so the height isn't definite) does exercise the AtMost → Exactly re-measure. Locally that gives counts of 1,2,3,4,5 by depth on both main and this PR, so it's linear rather than compounding. Note that the <= 2 per-level bound wouldn't hold there; the assertion would need to be something like <= depth + 1.

@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@Kunal22shah
Kunal22shah merged commit 73f4621 into main Oct 14, 2026
27 checks passed
@Kunal22shah
Kunal22shah deleted the dev/ks/flexpanel-row-item-width branch October 14, 2026 18:47
@kazo0

kazo0 commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

@Mergifyio backport servicing/10.0

@mergify

mergify Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

backport servicing/10.0

✅ Backports have been created

Details

Kunal22shah added a commit that referenced this pull request Oct 14, 2026
…item (backport #1676) (#1677)

* fix(flexpanel): size an inner panel to its content when it is a flex item

- a FlexPanel measured by a parent FlexPanel for content (AtMost/Undefined
  width) no longer fills the offered width; it was taking the whole line and
  leaving its Grow siblings with nothing
- mirrors the existing height-axis handling (_parentFlexHeightMode) for the
  width axis; HorizontalAlignment != Stretch still opts into fit-content
- tests: inner row item sized to content, growing inner item fills its share,
  inner panel in a centered column hugs its content

* refactor(flexpanel): name the height content flag after its axis

- outerFlexWantsContent becomes outerFlexWantsContentHeight beside the width one
- the measure-function comment now says both modes are handed to the child

* test(flexpanel): guard nested-panel sizing on both paths

- inner row item is content-sized with and without Shrink=0
- inner panel in a default stretch column still fills it
- centered inner panel's actual width hugs its content
- nested Grow rows keep each level at two measures or fewer

* docs(flexpanel): explain how nested panels size

(cherry picked from commit 73f4621)

Co-authored-by: Kunal Shah <[email protected]>
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.

[FlexPanel] A FlexPanel directly inside another FlexPanel fills the line instead of sizing to its content

4 participants