Skip to content

Commit 18f528d

Browse files
committed
Fix the HierarchicalMenu refienments logic
1 parent 8032ba1 commit 18f528d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

components/search/HierarchicalMenuWidget.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,18 @@ const MultiselectHierarchicalMenuItem = ({
312312

313313
const onButtonClick = useCallback(() => {
314314
if (isOpen) {
315-
// Clear all refinements
316-
levels.forEach(level => {
317-
level.items.forEach(subItem => {
318-
if (subItem.isRefined) {
319-
level.refine(subItem.name)
320-
}
321-
})
322-
})
315+
const currentLevel = levels[index]
316+
const subLevel = levels[index + 1]
317+
if (item.isRefined) {
318+
currentLevel.refine(item.name)
319+
}
320+
if (subLevel) {
321+
subLevel.items
322+
.filter(
323+
subItem => subItem.name.startsWith(item.name) && subItem.isRefined
324+
)
325+
.forEach(subItem => subLevel.refine(subItem.name))
326+
}
323327
}
324328
setIsOpen(!isOpen)
325329
}, [isOpen, levels])

0 commit comments

Comments
 (0)