diff --git a/resources/views/partials/sidebar.blade.php b/resources/views/partials/sidebar.blade.php index cc79059c..40b38a38 100644 --- a/resources/views/partials/sidebar.blade.php +++ b/resources/views/partials/sidebar.blade.php @@ -1172,14 +1172,57 @@ function filterMenus(query, skipSave) { } let matchCount = 0; + const groupHeaderMatches = new Set(); // 그룹 헤더가 매칭된 li 추적 - // 모든 메뉴 아이템 순회 + // 1단계: 그룹 헤더(대분류/서브그룹) 매칭 확인 + sidebarNav.querySelectorAll('li').forEach(li => { + const groupBtn = li.querySelector(':scope > button.sidebar-group-header, :scope > button.sidebar-subgroup-header'); + if (!groupBtn) return; + + const groupText = (groupBtn.querySelector('.sidebar-text')?.textContent || '').trim().toLowerCase(); + if (groupText.includes(query)) { + groupHeaderMatches.add(li); + } + }); + + // 2단계: 모든 메뉴 아이템 순회 const menuItems = sidebarNav.querySelectorAll('li'); menuItems.forEach(li => { + // 그룹 헤더가 매칭된 경우: 헤더 자체 + 모든 하위 메뉴 표시 + if (groupHeaderMatches.has(li)) { + li.style.display = ''; + li.classList.add('menu-search-match'); + li.classList.remove('menu-search-hidden'); + matchCount++; + + // 그룹 헤더에 하이라이트 적용 + const groupBtn = li.querySelector(':scope > button.sidebar-group-header, :scope > button.sidebar-subgroup-header'); + if (groupBtn) highlightText(groupBtn, query); + + // 하위 모든 메뉴 표시 + li.querySelectorAll('li').forEach(child => { + child.style.display = ''; + child.classList.remove('menu-search-hidden'); + }); + + // 부모 그룹들도 표시 + showParentGroups(li); + return; + } + + // 매칭된 그룹 헤더의 하위 항목이면 이미 처리됨 — 스킵 + let isChildOfMatchedGroup = false; + for (const matched of groupHeaderMatches) { + if (matched !== li && matched.contains(li)) { + isChildOfMatchedGroup = true; + break; + } + } + if (isChildOfMatchedGroup) return; + const link = li.querySelector('a[href], span[title]'); if (!link) { - // 그룹 헤더 등은 일단 숨김 li.style.display = 'none'; return; } @@ -1222,6 +1265,13 @@ function filterMenus(query, skipSave) { group.style.display = 'none'; } }); + + // 매칭된 그룹 헤더의 하위 그룹도 펼치기 + groupHeaderMatches.forEach(li => { + li.querySelectorAll('[id^="menu-group-"]').forEach(group => { + group.style.display = 'block'; + }); + }); } // 부모 그룹 표시