File tree 1 file changed +18
-1
lines changed
1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,22 @@ export var directive = {
12
12
acceptStatement : true ,
13
13
priority : 700 ,
14
14
15
+ bind : function ( ) {
16
+ var self = this ;
17
+
18
+ // @NOTE : Vue binds directives in microtasks, while UI events are dispatched
19
+ // in macrotasks. This causes the listener to be set up before
20
+ // the "origin" click event (the event that lead to the binding of
21
+ // the directive) arrives at the document root. To work around that,
22
+ // we ignore events until the end of the "initial" macrotask.
23
+ // @REFERENCE : https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/
24
+ // @REFERENCE : https://github.com/simplesmiler/vue-clickaway/issues/8
25
+ self . initialMacrotaskEnded = false ;
26
+ setTimeout ( function ( ) {
27
+ self . initialMacrotaskEnded = true ;
28
+ } ) ;
29
+ } ,
30
+
15
31
update : function ( handler ) {
16
32
if ( typeof handler !== 'function' ) {
17
33
if ( process . env . NODE_ENV !== 'production' ) {
@@ -26,13 +42,14 @@ export var directive = {
26
42
27
43
this . reset ( ) ;
28
44
45
+ var self = this ;
29
46
var el = this . el ;
30
47
var scope = this . _scope || this . vm ;
31
48
32
49
this . handler = function ( ev ) {
33
50
// @NOTE : IE 5.0+
34
51
// @REFERENCE : https://developer.mozilla.org/en/docs/Web/API/Node/contains
35
- if ( ! el . contains ( ev . target ) ) {
52
+ if ( self . initialMacrotaskEnded && ! el . contains ( ev . target ) ) {
36
53
scope . $event = ev ;
37
54
var res = handler ( ev ) ;
38
55
scope . $event = null ;
You can’t perform that action at this time.
0 commit comments