Skip to content

Commit

Permalink
Register listeners explicitly as not passive (#79)
Browse files Browse the repository at this point in the history
Listeners are preventing the default action in some conditions. Recent
Chrome versions have an intervention registering root-level listeners as
passive by default for some events. So listeners have to be declared as
non-passive explicitly.
  • Loading branch information
stof authored and davidtheclark committed Mar 21, 2019
1 parent de5d556 commit ecad453
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,22 @@ function focusTrap(element, userOptions) {
tryFocus(getInitialFocusNode());
});
doc.addEventListener('focusin', checkFocusIn, true);
doc.addEventListener('mousedown', checkPointerDown, true);
doc.addEventListener('touchstart', checkPointerDown, true);
doc.addEventListener('click', checkClick, true);
doc.addEventListener('keydown', checkKey, true);
doc.addEventListener('mousedown', checkPointerDown, {
capture: true,
passive: false
});
doc.addEventListener('touchstart', checkPointerDown, {
capture: true,
passive: false
});
doc.addEventListener('click', checkClick, {
capture: true,
passive: false
});
doc.addEventListener('keydown', checkKey, {
capture: true,
passive: false
});

return trap;
}
Expand Down

0 comments on commit ecad453

Please sign in to comment.