-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use { passive: false } in addEventListener to allow for preventDefault
Fixes #23. No functional change. https://developers.google.com/web/updates/2017/01/scrolling-intervention As of today, this has not been solved by React: facebook/react#8968
- Loading branch information
1 parent
742924a
commit 87a0e67
Showing
2 changed files
with
35 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// We want to make event listeners non-passive, and to do so have to check | ||
// that browsers support EventListenerOptions in the first place. | ||
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support | ||
let passiveSupported = false; | ||
try { | ||
const options = { | ||
get passive() { | ||
console.log("TRUE"); | ||
passiveSupported = true; | ||
} | ||
}; | ||
window.addEventListener("test", options, options); | ||
window.removeEventListener("test", options, options); | ||
} catch { | ||
console.log("FALSE"); | ||
passiveSupported = false; | ||
} | ||
|
||
function makePassiveEventOption(passive) { | ||
return passiveSupported ? { passive } : passive; | ||
} | ||
|
||
export default makePassiveEventOption; |