Skip to content

Commit

Permalink
fix(sidenavitems): remove conditional so children are always cloned (#…
Browse files Browse the repository at this point in the history
…15205)

* fix(sidenavitems): remove conditional so children are always cloned

* chore: remove test code
  • Loading branch information
tay1orjones committed Nov 14, 2023
1 parent e8e68df commit 979e44c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/react/src/components/UIShell/SideNavItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,14 @@ const SideNavItems: React.FC<SideNavItemsProps> = ({
const childrenWithExpandedState = React.Children.map(children, (child) => {
if (React.isValidElement(child)) {
// avoid spreading `isSideNavExpanded` to non-Carbon UI Shell children
const childType = child.type as React.ComponentType;
if (childType && childType.displayName) {
return React.cloneElement(child, {
...(CARBON_SIDENAV_ITEMS.includes(childType.displayName)
? {
isSideNavExpanded,
}
: {}),
});
}
const childDisplayName = (child.type as any)?.displayName;
return React.cloneElement(child, {
...(CARBON_SIDENAV_ITEMS.includes(childDisplayName)
? {
isSideNavExpanded,
}
: {}),
});
}
});
return <ul className={className}>{childrenWithExpandedState}</ul>;
Expand Down

0 comments on commit 979e44c

Please sign in to comment.