File tree Expand file tree Collapse file tree 2 files changed +21
-14
lines changed Expand file tree Collapse file tree 2 files changed +21
-14
lines changed Original file line number Diff line number Diff line change @@ -110,8 +110,8 @@ export default {
110
110
},
111
111
created () {
112
112
const hub = this .$root ;
113
- hub .$on (' show::modal' , id => id === this .id && this .show ());
114
- hub .$on (' hide::modal' , id => id === this .id && this .hide ());
113
+ hub .$on (' show::modal' , id => id === this .id && this .show ()). bind ( this ) ;
114
+ hub .$on (' hide::modal' , id => id === this .id && this .hide ()). bind ( this ) ;
115
115
},
116
116
mounted () {
117
117
document .addEventListener (' keydown' , this .pressedButton );
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<li :class =" {'nav-item': true, show: show,
3
3
dropdown: !dropup, dropup: dropup}" >
4
- <a @click.stop =" toggle($event)"
4
+ <a @click.stop.prevent =" toggle($event)"
5
5
:class =" ['nav-link', dropdownToggle]"
6
- href =" " v-on:click.prevent =" "
7
- aria-haspopup =" true"
6
+ href =" " aria-haspopup =" true"
8
7
:aria-expanded =" show"
9
8
:disabled =" disabled" >
10
9
<slot >{{ text }}</slot >
52
51
class: [' class' ]
53
52
},
54
53
methods: {
55
- toggle (e ) {
56
- // return if disabled
57
- if (this .disabled ) {
54
+ setShow (state ) {
55
+ if (this .show === state) {
58
56
return ;
59
- }
60
- // hide an alert
61
- this .show = ! this .show ;
62
- // Dispatch an event from the current vm that propagates all the way up to its $root
57
+ } // Avoid duplicated emits
58
+ this .show = state;
59
+
63
60
if (this .show ) {
64
61
this .$root .$emit (' shown::dropdown' );
65
- e .stopPropagation ();
66
62
} else {
67
63
this .$root .$emit (' hidden::dropdown' );
68
64
}
69
- }
65
+ },
66
+ toggle () {
67
+ this .setShow (! this .show );
68
+ },
69
+ clickOut () {
70
+ this .setShow (false );
71
+ },
70
72
},
71
73
created () {
72
74
const hub = this .$root ;
73
75
hub .$on (' hide::dropdown' , () => {
74
76
this .show = false ;
75
77
});
78
+ },
79
+ mounted () {
80
+ if (typeof document !== ' undefined' ) {
81
+ document .documentElement .addEventListener (' click' , this .clickOut );
82
+ }
76
83
}
77
84
};
78
85
</script >
You can’t perform that action at this time.
0 commit comments