Spaces:
Build error
Build error
File size: 443 Bytes
2cb745f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
export function clickOutside(element: HTMLDialogElement, callbackFunction: () => void) {
function onClick(event: MouseEvent) {
if (!element.contains(event.target as Node)) {
callbackFunction();
}
}
document.body.addEventListener("click", onClick);
return {
update(newCallbackFunction: () => void) {
callbackFunction = newCallbackFunction;
},
destroy() {
document.body.removeEventListener("click", onClick);
},
};
}
|