docs: improve ContextMenu example

This commit is contained in:
Benjamin Canac
2023-05-14 15:08:16 +02:00
parent cfcd2f1371
commit 6fd5a70ac9
2 changed files with 9 additions and 7 deletions

View File

@@ -1,11 +1,12 @@
<script setup>
const { x, y } = useMouse()
const { y: windowY } = useWindowScroll()
const isOpen = ref(false)
const virtualElement = ref({ getBoundingClientRect: () => ({}) })
function openContextMenu () {
const top = unref(y)
function onContextMenu () {
const top = unref(y) - unref(windowY)
const left = unref(x)
virtualElement.value.getBoundingClientRect = () => ({
@@ -20,8 +21,8 @@ function openContextMenu () {
</script>
<template>
<div class="w-full" @contextmenu.prevent="openContextMenu">
<Placeholder class="h-20 w-full flex items-center justify-center">
<div class="w-full" @contextmenu.prevent="onContextMenu">
<Placeholder class="h-96 select-none w-full flex items-center justify-center">
Right click here
</Placeholder>