Skip to content

Commit c84f0bd

Browse files
authored
fix: drawer close when clicked outside (#81)
1 parent 6e3bac2 commit c84f0bd

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/invoice-dashboard/src/lib/dashboard/drawer.svelte

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@
33
44
export let active = false;
55
export let onClose: () => void;
6+
7+
let drawerElement: HTMLElement;
68
</script>
79

8-
<div class={`drawer ${active ? "active" : "hidden"} `}>
10+
<div
11+
class={`drawer-overlay ${active ? "active" : "hidden"}`}
12+
on:click|stopPropagation={onClose}
13+
></div>
14+
<div bind:this={drawerElement} class={`drawer ${active ? "active" : "hidden"}`}>
915
<div class="innerDrawer">
1016
<button class="close" on:click={onClose} aria-label="Close drawer">
1117
<Close />
@@ -16,6 +22,16 @@
1622
</div>
1723

1824
<style>
25+
.drawer-overlay {
26+
position: fixed;
27+
top: 0;
28+
left: 0;
29+
right: 0;
30+
bottom: 0;
31+
background-color: rgba(0, 0, 0, 0.5);
32+
z-index: 200;
33+
}
34+
1935
.sr-only {
2036
position: absolute;
2137
width: 1px;
@@ -28,6 +44,7 @@
2844
border-width: 0;
2945
}
3046
.drawer {
47+
z-index: 1000;
3148
display: flex;
3249
position: absolute;
3350
top: 10px;

0 commit comments

Comments
 (0)