Skip to content

Commit 1c12060

Browse files
Subash-Mohansubash-onyx
authored andcommitted
Highlight active link in AdminSidebar based on current pathname (onyx-dot-app#4719)
* Highlight active link in AdminSidebar based on current pathname * Refactor AdminSidebar to declare pathname variable earlier --------- Co-authored-by: Subash <subash@onyx.app>
1 parent b588d12 commit 1c12060

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

web/src/components/admin/connectors/AdminSidebar.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"use client";
33
import React, { useContext } from "react";
44
import Link from "next/link";
5+
import { usePathname } from "next/navigation";
56
import { SettingsContext } from "@/components/settings/SettingsProvider";
67
import { CgArrowsExpandUpLeft } from "react-icons/cg";
78
import { LogoComponent } from "@/components/logo/FixedLogo";
@@ -19,10 +20,10 @@ interface Collection {
1920

2021
export function AdminSidebar({ collections }: { collections: Collection[] }) {
2122
const combinedSettings = useContext(SettingsContext);
23+
const pathname = usePathname() ?? "";
2224
if (!combinedSettings) {
2325
return null;
2426
}
25-
2627
const enterpriseSettings = combinedSettings.enterpriseSettings;
2728

2829
return (
@@ -57,7 +58,12 @@ export function AdminSidebar({ collections }: { collections: Collection[] }) {
5758
{collection.items.map((item) => (
5859
<Link key={item.link} href={item.link}>
5960
<button
60-
className={`text-sm text-text-700 block flex gap-x-2 items-center w-52 py-2.5 px-2 text-left hover:bg-background-settings-hover dark:hover:bg-neutral-800 rounded`}
61+
className={`text-sm text-text-700 block flex gap-x-2 items-center w-52 py-2.5 px-2 text-left hover:bg-background-settings-hover dark:hover:bg-neutral-800 rounded
62+
${
63+
pathname.startsWith(item.link)
64+
? "bg-background-settings-hover dark:bg-neutral-700"
65+
: ""
66+
}`}
6167
>
6268
{item.name}
6369
</button>

0 commit comments

Comments
 (0)