-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27429 from tienifr/fix/26990-warning-non-passive-…
…event-listener Fix: [Violation] Added non-passive event listener to a scroll-blocking 'wheel' event
- Loading branch information
Showing
6 changed files
with
38 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
8 changes: 8 additions & 0 deletions
8
src/libs/DeviceCapabilities/hasPassiveEventListenerSupport/index.native.ts
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,8 @@ | ||
import HasPassiveEventListenerSupport from './types'; | ||
|
||
/** | ||
* Allows us to identify whether the browser supports passive event listener. | ||
*/ | ||
const hasPassiveEventListenerSupport: HasPassiveEventListenerSupport = () => false; | ||
|
||
export default hasPassiveEventListenerSupport; |
18 changes: 18 additions & 0 deletions
18
src/libs/DeviceCapabilities/hasPassiveEventListenerSupport/index.ts
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,18 @@ | ||
/** | ||
* Allows us to identify whether the browser supports passive event listener. | ||
*/ | ||
export default function hasPassiveEventListenerSupport(): boolean { | ||
let supportsPassive = false; | ||
try { | ||
const opts = Object.defineProperty({}, 'passive', { | ||
// eslint-disable-next-line getter-return | ||
get() { | ||
supportsPassive = true; | ||
}, | ||
}); | ||
window.addEventListener('testPassive', () => {}, opts); | ||
window.removeEventListener('testPassive', () => {}, opts); | ||
// eslint-disable-next-line no-empty | ||
} catch (e) {} | ||
return supportsPassive; | ||
} |
3 changes: 3 additions & 0 deletions
3
src/libs/DeviceCapabilities/hasPassiveEventListenerSupport/types.ts
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,3 @@ | ||
type HasPassiveEventListenerSupport = () => boolean; | ||
|
||
export default HasPassiveEventListenerSupport; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import canUseTouchScreen from './canUseTouchScreen'; | ||
import hasHoverSupport from './hasHoverSupport'; | ||
import hasPassiveEventListenerSupport from './hasPassiveEventListenerSupport'; | ||
|
||
export {canUseTouchScreen, hasHoverSupport}; | ||
export {canUseTouchScreen, hasHoverSupport, hasPassiveEventListenerSupport}; |