@@ -4,6 +4,13 @@ export function clamp(number, lowerBound, upperBound) {
44 return Math . max ( lowerBound , Math . min ( number , upperBound ) ) ;
55}
66
7+ export const safePreventDefault = event => {
8+ const passiveEvents = [ "onTouchStart" , "onTouchMove" , "onWheel" ] ;
9+ if ( ! passiveEvents . includes ( event . _reactName ) ) {
10+ event . preventDefault ( ) ;
11+ }
12+ }
13+
714export const getOnDemandLazySlides = spec => {
815 let onDemandSlides = [ ] ;
916 let startIndex = lazyStartIndex ( spec ) ;
@@ -316,7 +323,7 @@ export const keyHandler = (e, accessibility, rtl) => {
316323} ;
317324
318325export const swipeStart = ( e , swipe , draggable ) => {
319- e . target . tagName === "IMG" && e . preventDefault ( ) ;
326+ e . target . tagName === "IMG" && safePreventDefault ( e ) ;
320327 if ( ! swipe || ( ! draggable && e . type . indexOf ( "mouse" ) !== - 1 ) ) return "" ;
321328 return {
322329 dragging : true ,
@@ -352,8 +359,8 @@ export const swipeMove = (e, spec) => {
352359 listWidth
353360 } = spec ;
354361 if ( scrolling ) return ;
355- if ( animating ) return e . preventDefault ( ) ;
356- if ( vertical && swipeToSlide && verticalSwiping ) e . preventDefault ( ) ;
362+ if ( animating ) return safePreventDefault ( e ) ;
363+ if ( vertical && swipeToSlide && verticalSwiping ) safePreventDefault ( e ) ;
357364 let swipeLeft ,
358365 state = { } ;
359366 let curLeft = getTrackLeft ( spec ) ;
@@ -421,7 +428,7 @@ export const swipeMove = (e, spec) => {
421428 }
422429 if ( touchObject . swipeLength > 10 ) {
423430 state [ "swiping" ] = true ;
424- e . preventDefault ( ) ;
431+ safePreventDefault ( e ) ;
425432 }
426433 return state ;
427434} ;
@@ -442,7 +449,7 @@ export const swipeEnd = (e, spec) => {
442449 infinite
443450 } = spec ;
444451 if ( ! dragging ) {
445- if ( swipe ) e . preventDefault ( ) ;
452+ if ( swipe ) safePreventDefault ( e ) ;
446453 return { } ;
447454 }
448455 let minSwipe = verticalSwiping
@@ -466,7 +473,7 @@ export const swipeEnd = (e, spec) => {
466473 return state ;
467474 }
468475 if ( touchObject . swipeLength > minSwipe ) {
469- e . preventDefault ( ) ;
476+ safePreventDefault ( e ) ;
470477 if ( onSwipe ) {
471478 onSwipe ( swipeDirection ) ;
472479 }
0 commit comments