File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 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) {
2828 return ;
2929 }
3030
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+
3143 el [ HANDLER ] = function ( ev ) {
3244 // @NOTE : IE 5.0+
3345 // @REFERENCE : https://developer.mozilla.org/en/docs/Web/API/Node/contains
34- if ( ! el . contains ( ev . target ) ) {
46+ if ( initialMacrotaskEnded && ! el . contains ( ev . target ) ) {
3547 return callback ( ev ) ;
3648 }
3749 } ;
You can’t perform that action at this time.
0 commit comments