Check if TouchEvent is defined first (#32)

When clicking on an image in the carousel with a mouse, a ReferenceError is thrown because TouchEvent is undefined.
This commit is contained in:
Andrew McGrath
2021-06-18 14:59:15 -04:00
committed by GitHub
parent f772fafc48
commit f3697d9783

View File

@@ -10,7 +10,7 @@ import {
import { createDispatcher } from '../../utils/event' import { createDispatcher } from '../../utils/event'
function getCoords(event) { function getCoords(event) {
if (event instanceof TouchEvent) { if ('TouchEvent' in window && event instanceof TouchEvent) {
const touch = event.touches[0] const touch = event.touches[0]
return { return {
x: touch ? touch.clientX : 0, x: touch ? touch.clientX : 0,