fix(web): context menu overlap + outclick types (#2506)

This commit is contained in:
Michel Heusschen 2023-05-21 18:01:08 +02:00 committed by GitHub
parent 96fb68135e
commit 85c6cf4309
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 52 deletions

View file

@ -1,5 +1,11 @@
export function clickOutside(node: Node) {
const handleClick = (event: Event) => {
import type { ActionReturn } from 'svelte/action';
interface Attributes {
'on:outclick'?: (e: CustomEvent) => void;
}
export function clickOutside(node: HTMLElement): ActionReturn<void, Attributes> {
const handleClick = (event: MouseEvent) => {
const targetNode = event.target as Node | null;
if (!node.contains(targetNode)) {
node.dispatchEvent(new CustomEvent('outclick'));
@ -7,7 +13,7 @@ export function clickOutside(node: Node) {
};
const handleKey = (event: KeyboardEvent) => {
if (event.key == 'Escape') {
if (event.key === 'Escape') {
node.dispatchEvent(new CustomEvent('outclick'));
}
};