fix: open navigation item by default (#716)

This commit is contained in:
Manuel
2024-06-26 12:19:05 +02:00
committed by GitHub
parent 988ec6bebb
commit c4b54ed36c

View File

@@ -35,19 +35,24 @@ const NavLinkHref = (props: NavigationLinkHref) => {
); );
}; };
const NavLinkWithItems = (props: NavigationLinkWithItems) => ( const NavLinkWithItems = (props: NavigationLinkWithItems) => {
const pathname = usePathname();
const isActive = props.items.some((item) => item.href === pathname);
return (
<NavLink <NavLink
style={{ style={{
borderRadius: 5, borderRadius: 5,
}} }}
label={props.label} label={props.label}
leftSection={props.icon} leftSection={props.icon}
defaultOpened={isActive}
> >
{props.items.map((item) => ( {props.items.map((item) => (
<NavLinkHref key={item.label} {...item} /> <NavLinkHref key={item.label} {...item} />
))} ))}
</NavLink> </NavLink>
); );
};
interface CommonNavigationLinkProps { interface CommonNavigationLinkProps {
label: string; label: string;