{children}
diff --git a/packages/common/components/src/ui/lnb/index.tsx b/packages/common/components/src/ui/lnb/index.tsx
index b1a7fe094..197a44a9e 100644
--- a/packages/common/components/src/ui/lnb/index.tsx
+++ b/packages/common/components/src/ui/lnb/index.tsx
@@ -1,7 +1,7 @@
import { useState } from "react";
import { useQuery } from "@tanstack/react-query";
import { ChevronRight } from "lucide-react";
-import { cn } from "../../lib/utils";
+import { cn, setCookie } from "../../lib";
import { ENDPOINT, SITE_ID } from "../../config";
import { getMenuList, type MenuItem } from "../../api";
import {
@@ -19,7 +19,15 @@ import {
} from "../collapsible";
import { getParentIds } from "./lib";
-export function LNB({ viewOnly }: { viewOnly?: boolean }) {
+export function LNB({
+ viewOnly,
+ currentPath,
+ routeHandler,
+}: {
+ viewOnly?: boolean;
+ currentPath?: string;
+ routeHandler?: (path: string) => void;
+}) {
const { data: menuList } = useQuery({
queryKey: [ENDPOINT.CMS_SERVICE.MENU_ROLES],
queryFn: () => getMenuList(SITE_ID),
@@ -28,14 +36,31 @@ export function LNB({ viewOnly }: { viewOnly?: boolean }) {
const [openMenuIds, setOpenMenuIds] = useState([]);
+ function isPathMatched(path: string) {
+ return currentPath === path || currentPath?.startsWith(`${path}/`);
+ }
+
function MenuItem({ item }: { item: MenuItem }) {
+ const isMatched = isPathMatched(item.urlPath);
+
+ const handleClick = () => {
+ setCookie("menu-code-key", item.menuCd.toString());
+ routeHandler?.(item.urlPath);
+ };
+
if (item.children) {
return ;
}
return (
-
+
{item.menuKornNm}
@@ -44,7 +69,11 @@ export function LNB({ viewOnly }: { viewOnly?: boolean }) {
}
function MenuGroup({ item }: { item: MenuItem }) {
- const isOpen = openMenuIds.includes(item.menuCd);
+ const hasMatchedChild = item.children?.some((child) =>
+ isPathMatched(child.urlPath),
+ );
+
+ const isOpen = openMenuIds.includes(item.menuCd) || hasMatchedChild;
const handleOpenChange = (open: boolean) => {
if (open) {