Skip to content

Commit 578712c

Browse files
committed
fix: useMatch to apply active styling
1 parent bc90de9 commit 578712c

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

site/src/components/Sidebar/Sidebar.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { CSSObject, Interpolation, Theme } from "@emotion/react";
33
import { Stack } from "components/Stack/Stack";
44
import { type ClassName, useClassName } from "hooks/useClassName";
55
import type { ElementType, FC, ReactNode } from "react";
6-
import { Link, NavLink, useLocation } from "react-router-dom";
6+
import { Link, NavLink, useMatch } from "react-router-dom";
77
import { cn } from "utils/cn";
88

99
interface SidebarProps {
@@ -61,18 +61,8 @@ export const SettingsSidebarNavItem: FC<SettingsSidebarNavItemProps> = ({
6161
href,
6262
end,
6363
}) => {
64+
const matchResult = useMatch(href);
6465

65-
const location = useLocation();
66-
if (end) {
67-
console.log('Current Path:', location.pathname);
68-
console.log('NavLink href:', href);
69-
}
70-
71-
const normalizePath = (path: string) =>
72-
path.endsWith('/') ? path.slice(0, -1) : path;
73-
74-
const isInitiallyActive =
75-
normalizePath(location.pathname) === normalizePath(href);
7666
return (
7767
<NavLink
7868
end={end}
@@ -81,7 +71,7 @@ export const SettingsSidebarNavItem: FC<SettingsSidebarNavItemProps> = ({
8171
cn(
8272
"relative text-sm text-content-secondary no-underline font-medium py-2 px-3 hover:bg-surface-secondary rounded-md transition ease-in-out duration-150",
8373
{
84-
"font-semibold text-content-primary": isActive || isInitiallyActive,
74+
"font-semibold text-content-primary": matchResult !== null,
8575
},
8676
)
8777
}

0 commit comments

Comments
 (0)