Skip to content

Commit

Permalink
Move back to minimize diff
Browse files Browse the repository at this point in the history
  • Loading branch information
khiga8 committed Jun 27, 2024
1 parent 057ff7c commit 646110e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/react/src/NavList/NavList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,19 @@ const Item = React.forwardRef<HTMLAnchorElement, NavListItemProps>(
// Get SubNav from children
const subNav = React.Children.toArray(children).find(child => isValidElement(child) && child.type === SubNav)

// Get children without SubNav or TrailingAction
const childrenWithoutSubNavOrTrailingAction = React.Children.toArray(children).filter(child =>
isValidElement(child) ? child.type !== SubNav && child.type !== TrailingAction : true,
)

if (!isValidElement(subNav) && defaultOpen)
// eslint-disable-next-line no-console
console.error('NavList.Item must have a NavList.SubNav to use defaultOpen.')

// Render ItemWithSubNav if SubNav is present
if (subNav && isValidElement(subNav)) {
// Filter out TrailingAction
const childrenWithoutSubNavOrTrailingAction = React.Children.toArray(children).filter(child =>
isValidElement(child) ? child.type !== SubNav && child.type !== TrailingAction : true,
)

return (
<ItemWithSubNav subNav={subNav} depth={depth} defaultOpen={defaultOpen} sx={sxProp}>
{/* This is a trailing action */}
{childrenWithoutSubNavOrTrailingAction}
</ItemWithSubNav>
)
Expand Down

0 comments on commit 646110e

Please sign in to comment.