Skip to content

Commit f58713e

Browse files
committed
Try to use path, then composed path, then fallback to contains
1 parent 7dbe5da commit f58713e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ function bind(el, binding) {
4141
}, 0);
4242

4343
el[HANDLER] = function(ev) {
44-
// @NOTE: this test used to be `el.containts`, but `ev.path` is better,
44+
// @NOTE: this test used to be just `el.containts`, but working with path is better,
4545
// because it tests whether the element was there at the time of
4646
// the click, not whether it is there now, that the event has arrived
4747
// to the top.
48-
if (initialMacrotaskEnded && ev.path.indexOf(el) < 0) {
48+
// @NOTE: `.path` is non-standard, the standard way is `.composedPath()`
49+
var path = ev.path || (ev.composedPath ? ev.composedPath() : undefined);
50+
if (initialMacrotaskEnded && (path ? path.indexOf(el) < 0 : !el.contains(ev.target))) {
4951
return callback(ev);
5052
}
5153
};

0 commit comments

Comments
 (0)