File tree Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Expand file tree Collapse file tree 2 files changed +20
-12
lines changed Original file line number Diff line number Diff line change 78
78
document .documentElement .addEventListener (' click' , this .clickOut );
79
79
}
80
80
},
81
+ created () {
82
+ this .$root .$on (' shown::dropdown' , el => {
83
+ if (el !== this ) {
84
+ this .clickOut ();
85
+ }
86
+ });
87
+ },
81
88
methods: {
82
89
toggle () {
83
90
this .setShow (! this .show );
84
91
},
85
92
setShow (state ) {
86
93
if (this .show === state) {
87
- return ;
88
- } // Avoid duplicated emits
94
+ return ; // Avoid duplicated emits
95
+ }
89
96
this .show = state;
90
97
91
98
if (this .show ) {
92
- this .$emit (' shown' );
99
+ this .$root . $ emit (' shown::dropdown ' , this );
93
100
} else {
94
- this .$emit (' hidden' );
101
+ this .$root . $ emit (' hidden::dropdown ' , this );
95
102
}
96
103
},
97
104
clickOut () {
Original file line number Diff line number Diff line change 52
52
methods: {
53
53
setShow (state ) {
54
54
if (this .show === state) {
55
- return ;
56
- } // Avoid duplicated emits
55
+ return ; // Avoid duplicated emits
56
+ }
57
57
this .show = state;
58
58
59
59
if (this .show ) {
60
- this .$root .$emit (' shown::dropdown' );
60
+ this .$root .$emit (' shown::dropdown' , this );
61
61
} else {
62
- this .$root .$emit (' hidden::dropdown' );
62
+ this .$root .$emit (' hidden::dropdown' , this );
63
63
}
64
64
},
65
65
toggle () {
70
70
}
71
71
},
72
72
created () {
73
- const hub = this .$root ;
74
- hub .$on (' hide::dropdown' , () => {
75
- this .show = false ;
73
+ this .$root .$on (' shown::dropdown' , el => {
74
+ if (el !== this ) {
75
+ this .clickOut ();
76
+ }
76
77
});
77
78
},
78
79
mounted () {
79
80
if (typeof document !== ' undefined' ) {
80
- document .documentElement .addEventListener (' click' , this .clickOut , true );
81
+ document .documentElement .addEventListener (' click' , this .clickOut );
81
82
}
82
83
}
83
84
};
You can’t perform that action at this time.
0 commit comments