inference-api / src /lib /utils /clickOutside.js
enzostvs's picture
enzostvs HF staff
responsive menu
fbf8165
raw
history blame contribute delete
345 Bytes
export function clickOutside(node) {
window.addEventListener('click', handleClick);
function handleClick(e){
if (!node.contains(e.target)){
node.dispatchEvent(new CustomEvent('outsideclick'))
}
}
return {
destroy() {
// the node has been removed from the DOM
window.removeEventListener('click', handleClick)
}
};
}