File tree Expand file tree Collapse file tree 4 files changed +30
-8
lines changed
packages/floating-vue/src/directives Expand file tree Collapse file tree 4 files changed +30
-8
lines changed Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" example flex justify-center" >
3
+ <VDropdown >
4
+ <button class =" border border-gray-500 rounded px-4 py-2" >
5
+ Click me
6
+ </button >
7
+
8
+ <template #popper >
9
+ <div class =" p-6 flex gap-2" >
10
+ <button class =" underline cursor-pointer" >Other button</button >
11
+ <button v-close-popper class =" underline cursor-pointer" >Close</button >
12
+ </div >
13
+ </template >
14
+ </VDropdown >
15
+ </div >
16
+ </template >
Original file line number Diff line number Diff line change @@ -8,9 +8,11 @@ export {}
8
8
declare module 'vue' {
9
9
export interface GlobalComponents {
10
10
ArrowPadding : typeof import ( './.vitepress/components/ArrowPadding.vue' ) [ 'default' ]
11
+ DropdownCloseDirectiveDemo : typeof import ( './.vitepress/components/DropdownCloseDirectiveDemo.vue' ) [ 'default' ]
11
12
DropdownMobileDemo : typeof import ( './.vitepress/components/DropdownMobileDemo.vue' ) [ 'default' ]
12
13
DropdownPlacement : typeof import ( './.vitepress/components/DropdownPlacement.vue' ) [ 'default' ]
13
14
DropdownSimpleExample : typeof import ( './.vitepress/components/DropdownSimpleExample.vue' ) [ 'default' ]
15
+ DropdownVClodePopperDemo : typeof import ( './.vitepress/components/DropdownVClodePopperDemo.vue' ) [ 'default' ]
14
16
MenuSimpleExample : typeof import ( './.vitepress/components/MenuSimpleExample.vue' ) [ 'default' ]
15
17
OffsetExample : typeof import ( './.vitepress/components/OffsetExample.vue' ) [ 'default' ]
16
18
RouterLink : typeof import ( 'vue-router' ) [ 'RouterLink' ]
Original file line number Diff line number Diff line change @@ -218,7 +218,7 @@ Use the `hide` slot prop to close the popper:
218
218
<button >Click me</button >
219
219
220
220
<template #popper =" { hide }" >
221
- <a @click =" hide()" >Close</a >
221
+ <button @click =" hide()" >Close</button >
222
222
</template >
223
223
</VDropdown >
224
224
```
@@ -232,24 +232,26 @@ Use the `v-close-popper` directive on an element inside the dropdown to close it
232
232
<button >Click me</button >
233
233
234
234
<template #popper >
235
- <a v-close-popper >Close</a >
235
+ <button v-close-popper >Close</button >
236
236
</template >
237
237
</VDropdown >
238
238
```
239
239
240
+ <DropdownCloseDirectiveDemo />
241
+
240
242
The directive works even in nested components in the ` popper ` slot.
241
243
242
244
You can also set it to true or false to enable or disable the directive (enabled by default):
243
245
244
246
``` html
245
- <a v-close-popper =" false" >Close</a >
246
- <a v-close-popper =" true" >Close</a >
247
+ <button v-close-popper =" false" >Close</button >
248
+ <button v-close-popper =" true" >Close</button >
247
249
```
248
250
249
251
You can also use a property:
250
252
251
253
``` html
252
- <a v-close-popper =" myBooleanProp" >Close</a >
254
+ <button v-close-popper =" myBooleanProp" >Close</button >
253
255
```
254
256
255
257
``` js
Original file line number Diff line number Diff line change 1
1
import { supportsPassive } from '../util/env'
2
2
3
3
function addListeners ( el ) {
4
- el . addEventListener ( 'mousedown' , onMouseDown )
4
+ el . addEventListener ( 'mousedown' , addEventProps )
5
+ el . addEventListener ( 'click' , addEventProps )
5
6
el . addEventListener ( 'touchstart' , onTouchStart , supportsPassive
6
7
? {
7
8
passive : true ,
@@ -10,13 +11,14 @@ function addListeners (el) {
10
11
}
11
12
12
13
function removeListeners ( el ) {
13
- el . removeEventListener ( 'mousedown' , onMouseDown )
14
+ el . removeEventListener ( 'mousedown' , addEventProps )
15
+ el . removeEventListener ( 'click' , addEventProps )
14
16
el . removeEventListener ( 'touchstart' , onTouchStart )
15
17
el . removeEventListener ( 'touchend' , onTouchEnd )
16
18
el . removeEventListener ( 'touchcancel' , onTouchCancel )
17
19
}
18
20
19
- function onMouseDown ( event ) {
21
+ function addEventProps ( event ) {
20
22
const el = event . currentTarget
21
23
event . closePopover = ! el . $_vclosepopover_touch
22
24
event . closeAllPopover = el . $_closePopoverModifiers && ! ! el . $_closePopoverModifiers . all
You can’t perform that action at this time.
0 commit comments