File tree 1 file changed +13
-1
lines changed
1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -28,10 +28,22 @@ function bind(el, binding) {
28
28
return ;
29
29
}
30
30
31
+ // @NOTE : Vue binds directives in microtasks, while UI events are dispatched
32
+ // in macrotasks. This causes the listener to be set up before
33
+ // the "origin" click event (the event that lead to the binding of
34
+ // the directive) arrives at the document root. To work around that,
35
+ // we ignore events until the end of the "initial" macrotask.
36
+ // @REFERENCE : https://jakearchibald.com/2015/tasks-microtasks-queues-and-schedules/
37
+ // @REFERENCE : https://github.com/simplesmiler/vue-clickaway/issues/8
38
+ var initialMacrotaskEnded = false ;
39
+ setTimeout ( function ( ) {
40
+ initialMacrotaskEnded = true ;
41
+ } , 0 ) ;
42
+
31
43
el [ HANDLER ] = function ( ev ) {
32
44
// @NOTE : IE 5.0+
33
45
// @REFERENCE : https://developer.mozilla.org/en/docs/Web/API/Node/contains
34
- if ( ! el . contains ( ev . target ) ) {
46
+ if ( initialMacrotaskEnded && ! el . contains ( ev . target ) ) {
35
47
return callback ( ev ) ;
36
48
}
37
49
} ;
You can’t perform that action at this time.
0 commit comments