File tree Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Expand file tree Collapse file tree 2 files changed +74
-0
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <v-container max-width =" 300" >
3
+ <div
4
+ v-for =" n in 10"
5
+ :key =" n"
6
+ class =" py-2 border-b d-flex align-center ga-2"
7
+ >
8
+ Some Text Here
9
+ <v-spacer ></v-spacer >
10
+ <v-icon-btn
11
+ icon =" mdi-dots-vertical"
12
+ size =" small"
13
+ variant =" outlined"
14
+ @click =" show"
15
+ ></v-icon-btn >
16
+ </div >
17
+
18
+ <v-menu
19
+ v-model =" showMenu"
20
+ :offset =" [-8,-12]"
21
+ :target =" menuTarget"
22
+ location =" bottom end"
23
+ scroll-strategy =" close"
24
+ >
25
+ <v-list
26
+ :items =" menuItems"
27
+ class =" py-0"
28
+ density =" compact"
29
+ item-value =" code"
30
+ item-props
31
+ slim
32
+ >
33
+ <template v-slot :prepend >
34
+ <v-icon class =" mr-n2" size =" small" ></v-icon >
35
+ </template >
36
+ </v-list >
37
+ </v-menu >
38
+ </v-container >
39
+ </template >
40
+
41
+ <script setup>
42
+ import { ref } from ' vue'
43
+
44
+ const showMenu = ref (false )
45
+ const menuTarget = ref (null )
46
+
47
+ const menuItems = [
48
+ { title: ' Create' , prependIcon: ' mdi-plus-circle-outline' , code: ' add' },
49
+ { type: ' divider' },
50
+ { title: ' Modify' , prependIcon: ' mdi-pencil-outline' , code: ' edit' },
51
+ { type: ' divider' },
52
+ { title: ' Remove' , prependIcon: ' mdi-trash-can-outline' , code: ' delete' },
53
+ ]
54
+
55
+ async function show (evt ) {
56
+ if (showMenu .value ) {
57
+ showMenu .value = false
58
+ await new Promise (r => setTimeout (r, 100 ))
59
+ }
60
+ menuTarget .value = evt .target .closest (' .v-icon-btn' )
61
+ showMenu .value = true
62
+ }
63
+ </script >
Original file line number Diff line number Diff line change @@ -97,6 +97,17 @@ Menus with other menus inside them will not close until their children are close
97
97
98
98
<ExamplesExample file =" v-menu/prop-submenu " />
99
99
100
+ #### Positioning Menus with Coordinates
101
+
102
+ ` v-menu ` can be positioned relative to a DOM element or explicit ` [x, y] ` coordinates.
103
+
104
+ * The most common use case is to pass an ** event target element** . This allows the menu to anchor itself to the element that was clicked.
105
+ * You can also use ` [x, y] ` screen coordinates, though this is less common and typically used for context menus.
106
+ * ` :offset ` is used to shift the menu position relative to its anchor, not to define an absolute position.
107
+ * Any DOM event with ` clientX ` and ` clientY ` can be used (e.g. ` click ` , ` contextmenu ` ).
108
+
109
+ <ExamplesExample file =" v-menu/prop-positioningmenu " />
110
+
100
111
### Slots
101
112
102
113
#### Activator and tooltip
You can’t perform that action at this time.
0 commit comments