mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-14 11:33:49 +00:00
refactor(#35): click anywhere handler
This commit is contained in:
@@ -15,9 +15,10 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
const handleClickAnywhere = (event: MouseEvent) => {
|
const handleClickAnywhere = ({ target }: MouseEvent) => {
|
||||||
if (!isOpen) return;
|
if (!isOpen || !target) return;
|
||||||
if (!dropdown.contains(event.target as Node) || event.target instanceof HTMLAnchorElement) {
|
const clickTarget = target as HTMLElement;
|
||||||
|
if (!dropdown.contains(clickTarget) || clickTarget.closest('a')) {
|
||||||
isOpen = false;
|
isOpen = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user