chore: consider "contextmenu" event as a click outside event too

This commit is contained in:
Meesayen 2024-02-19 14:29:04 +01:00 committed by Mattias Granlund
parent 52607dfb75
commit 0fddf1bc5b

View File

@ -15,15 +15,19 @@ export function clickOutside(
} }
} }
document.addEventListener('click', onClick, true); document.addEventListener('click', onClick, true);
document.addEventListener('contextmenu', onClick, true);
return { return {
destroy() { destroy() {
document.removeEventListener('click', onClick, true); document.removeEventListener('click', onClick, true);
document.removeEventListener('contextmenu', onClick, true);
}, },
update(opts: ClickOpts) { update(opts: ClickOpts) {
document.removeEventListener('click', onClick, true); document.removeEventListener('click', onClick, true);
document.removeEventListener('contextmenu', onClick, true);
if (opts.enabled !== undefined && !opts.enabled) return; if (opts.enabled !== undefined && !opts.enabled) return;
trigger = opts.trigger; trigger = opts.trigger;
document.addEventListener('click', onClick, true); document.addEventListener('click', onClick, true);
document.addEventListener('contextmenu', onClick, true);
} }
}; };
} }