fix(fuselage): do not render GridItem for null or boolean children in CardGrid

AR
19d ago
+23-1

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

  1. Render with conditional children:
    ` sx
Card 1 {false && Card 2} {null} Card 3 ` 2. Before: DOM contains 4 .rcx-card-grid__item elements (2 of which are empty padded containers). 3. After: DOM contains exactly 2 .rcx-card-grid__item elements.

Further comments

Follows the solution outlined by @tassoevan in #42804.

Summary by CodeRabbit

  • Bug Fixes
    • Card grids now skip boolean children, alongside null and undefined, 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.