Skip to content

fix(Navigation): active state #5270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: beta
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-paths-stick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ultraviolet/plus": patch
---

`Navigation`: isActive should work when the Item is wrapped in a Link/NavLink (React rooter)
22 changes: 18 additions & 4 deletions packages/plus/src/components/Navigation/components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ const StyledMenuItem = styled(Menu.Item, {
}

${StyledBadge} {
opacity: ${({ isPinnable, pinnedFeature }) => (isPinnable && pinnedFeature ? 0 : 1)};
opacity: ${({ isPinnable, pinnedFeature }) =>
isPinnable && pinnedFeature ? 0 : 1};
}
}
`
Expand Down Expand Up @@ -265,6 +266,10 @@ const ContainerCategoryIcon = styled(Stack)`

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

type LinkProps = {
to: string
children?: { props: ItemProps }
}
type ItemProps = {
children?: ReactNode
/**
Expand Down Expand Up @@ -437,9 +442,18 @@ export const Item = memo(
if (!children) return false

return (
Children.map(children, child =>
isValidElement<ItemProps>(child) ? child.props?.active : false,
) as boolean[]
Children.map(children, child => {
if (isValidElement<ItemProps | LinkProps>(child)) {
// In case the Item is wrapped in a link
if ('to' in child.props) {
return child.props.children?.props.active
}

return child.props.active
}

return null
}) as boolean[]
).includes(true)
}, [children])

Expand Down
Loading