mirror of https://github.com/sveltejs/svelte
16 lines
322 B
16 lines
322 B
3 years ago
|
export function clickOutside(node) {
|
||
|
const handleClick = (event) => {
|
||
|
if (!node.contains(event.target)) {
|
||
2 years ago
|
node.dispatchEvent(new CustomEvent('outclick'));
|
||
3 years ago
|
}
|
||
|
};
|
||
|
|
||
2 years ago
|
document.addEventListener('click', handleClick, true);
|
||
3 years ago
|
|
||
|
return {
|
||
|
destroy() {
|
||
2 years ago
|
document.removeEventListener('click', handleClick, true);
|
||
3 years ago
|
}
|
||
|
};
|
||
|
}
|