Skip to content

Commit 0e7b066

Browse files
authored
fix: navigation active (#5270)
1 parent c15ac12 commit 0e7b066

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

.changeset/rude-paths-stick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/plus": patch
3+
---
4+
5+
`Navigation`: isActive should work when the Item is wrapped in a Link/NavLink (React rooter)

packages/plus/src/components/Navigation/components/Item.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ const StyledMenuItem = styled(Menu.Item, {
116116
}
117117
118118
${StyledBadge} {
119-
opacity: ${({ isPinnable, pinnedFeature }) => (isPinnable && pinnedFeature ? 0 : 1)};
119+
opacity: ${({ isPinnable, pinnedFeature }) =>
120+
isPinnable && pinnedFeature ? 0 : 1};
120121
}
121122
}
122123
`
@@ -265,6 +266,10 @@ const ContainerCategoryIcon = styled(Stack)`
265266

266267
type ItemType = 'default' | 'pinned' | 'pinnedGroup'
267268

269+
type LinkProps = {
270+
to: string
271+
children?: { props: ItemProps }
272+
}
268273
type ItemProps = {
269274
children?: ReactNode
270275
/**
@@ -437,9 +442,18 @@ export const Item = memo(
437442
if (!children) return false
438443

439444
return (
440-
Children.map(children, child =>
441-
isValidElement<ItemProps>(child) ? child.props?.active : false,
442-
) as boolean[]
445+
Children.map(children, child => {
446+
if (isValidElement<ItemProps | LinkProps>(child)) {
447+
// In case the Item is wrapped in a link
448+
if ('to' in child.props) {
449+
return child.props.children?.props.active
450+
}
451+
452+
return child.props.active
453+
}
454+
455+
return null
456+
}) as boolean[]
443457
).includes(true)
444458
}, [children])
445459

0 commit comments

Comments
 (0)