refactor(#35): click anywhere handler

This commit is contained in:
OllyNicholass
2024-11-18 23:20:18 +00:00
parent ffde37ed15
commit 0189b20e0c
+4 -3
View File
@@ -15,9 +15,10 @@
};
onMount(() => {
const handleClickAnywhere = (event: MouseEvent) => {
if (!isOpen) return;
if (!dropdown.contains(event.target as Node) || event.target instanceof HTMLAnchorElement) {
const handleClickAnywhere = ({ target }: MouseEvent) => {
if (!isOpen || !target) return;
const clickTarget = target as HTMLElement;
if (!dropdown.contains(clickTarget) || clickTarget.closest('a')) {
isOpen = false;
}
};