fix(fuselage): do not render GridItem for null or boolean children in CardGrid
AR
19d ago+23+23+01234567890123456789-1-1-0123456789
Proposed changes (including videos or screenshots)
CardGrid previously wrapped each child using Children.map(children, ...). Because Children.map visits
ull, undefined, and boolean values, conditionally rendered cards such as {condition && } caused an empty, padded to be rendered into the DOM.
This PR updates CardGrid to iterate over Children.toArray(children) instead. Children.toArray strips out empty, null, and boolean children, so only genuine card items are wrapped in a .
- Replaced Children.map with Children.toArray(children).map(...) in packages/fuselage/src/components/CardGrid/CardGrid.tsx.
- Assigned unique key from child element or index to each .
- Added unit regression test in CardGrid.spec.tsx verifying that
ull, undefined, and boolean children do not produce elements. - Added changeset file .changeset/fuselage-cardgrid-null-children.md.
Issue(s)
Closes #42804
Steps to test or reproduce
- Render with conditional children:
` sx
Further comments
Follows the solution outlined by @tassoevan in #42804.
Summary by CodeRabbit
- Bug Fixes
- Card grids now skip boolean children, alongside
nullandundefined, instead of creating grid items for them. Element children continue to render as grid items, and other child handling remains unchanged. This keeps non-element values from appearing as visible card grid content.
- Card grids now skip boolean children, alongside