Skip to content

Commit 8fae4fd

Browse files
authored
fix: Pop-over is not closed when selecting facet (#720)
1 parent 7c1557c commit 8fae4fd

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/routes/products/search/FacetCard.svelte

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,26 @@
1515
} = $props();
1616
1717
let showAll: boolean = $state(false);
18+
let dropdownElement: HTMLDetailsElement;
19+
1820
function toggleShowAll() {
1921
showAll = !showAll;
2022
}
2123
24+
function handleSelect(item: FacetItem) {
25+
onSelect(item);
26+
if (dropdownElement) {
27+
dropdownElement.open = false;
28+
}
29+
}
30+
31+
function handleUnselect(item: FacetItem) {
32+
onUnselect(item);
33+
if (dropdownElement) {
34+
dropdownElement.open = false;
35+
}
36+
}
37+
2238
let searchQuery: string = $state('');
2339
let visibleValues = $derived.by(() => {
2440
if (searchQuery) {
@@ -35,7 +51,7 @@
3551
});
3652
</script>
3753

38-
<details class="dropdown dropdown-center">
54+
<details class="dropdown dropdown-center" bind:this={dropdownElement}>
3955
<summary class="btn flex w-58 items-center justify-start gap-2">
4056
{facet.name} ({facet.items.length})
4157
<span class="flex-grow"></span>
@@ -60,9 +76,9 @@
6076
onchange={(e) => {
6177
const isSelected = e.currentTarget.checked;
6278
if (isSelected) {
63-
onSelect(item);
79+
handleSelect(item);
6480
} else {
65-
onUnselect(item);
81+
handleUnselect(item);
6682
}
6783
}}
6884
/>

0 commit comments

Comments
 (0)