use @vueuse/useClickOutside to hide context menu

This commit is contained in:
geoffrey45
2022-10-08 20:05:16 +03:00
committed by Mungai Njoroge
parent a496d68439
commit 4e0837a627
4 changed files with 24 additions and 12 deletions
+22 -1
View File
@@ -1,6 +1,7 @@
<template>
<div
class="context-menu rounded shadow-lg"
ref="contextMenu"
:class="[
{ 'context-menu-visible': context.visible },
{ 'context-normalizedX': context.normalizedX },
@@ -29,10 +30,30 @@
</template>
<script setup lang="ts">
import { ref } from "vue";
import { onClickOutside } from "@vueuse/core";
import useContextStore from "../stores/context";
import ContextItem from "./Contextmenu/ContextItem.vue";
const context = useContextStore();
const contextMenu = ref<HTMLElement>();
let clickCount = 0;
onClickOutside(contextMenu, (e) => {
if (!context.visible) {
clickCount = 0;
return;
}
clickCount++;
if (context.visible && clickCount == 2) {
context.hideContextMenu();
e.stopImmediatePropagation();
clickCount = 0;
}
});
</script>
<style lang="scss">