Skip to content
This repository has been archived by the owner on Sep 12, 2024. It is now read-only.

Commit

Permalink
feat: added handler for outside clicking userinfo (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
prasarCodes authored May 13, 2023
1 parent 8979573 commit 15f77a5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/lib/components/profile-picture.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { beforeNavigate } from '$app/navigation';
import { createPopper, type Instance } from '@popperjs/core';
import { tick } from 'svelte';
import { tick, onMount } from 'svelte';
export let username: string;
let displayPopover = false;
Expand Down Expand Up @@ -43,6 +43,23 @@
}
}
function handleOutsideClick(event: MouseEvent) {
if (root && popover) {
const target = event.target as Node;
if (!root.contains(target) && !popover.contains(target)) {
displayPopover = false;
destroyInstance();
}
}
}
onMount(() => {
window.addEventListener('click', handleOutsideClick);
return () => {
window.removeEventListener('click', handleOutsideClick);
};
});
let root: HTMLElement;
let popover: HTMLElement;
</script>
Expand Down

0 comments on commit 15f77a5

Please sign in to comment.