fix: [sidebar] 메뉴 검색 시 대분류 그룹도 검색 대상에 포함
- 그룹 헤더(대분류/서브그룹)도 검색어 매칭 대상으로 추가 - 그룹 헤더 매칭 시 하위 전체 메뉴 표시 + 하이라이트 적용
This commit is contained in:
@@ -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';
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 부모 그룹 표시
|
||||
|
||||
Reference in New Issue
Block a user