@@ -4,6 +4,13 @@ export function clamp(number, lowerBound, upperBound) {
4
4
return Math . max ( lowerBound , Math . min ( number , upperBound ) ) ;
5
5
}
6
6
7
+ export const safePreventDefault = event => {
8
+ const passiveEvents = [ "onTouchStart" , "onTouchMove" , "onWheel" ] ;
9
+ if ( ! passiveEvents . includes ( event . _reactName ) ) {
10
+ event . preventDefault ( ) ;
11
+ }
12
+ }
13
+
7
14
export const getOnDemandLazySlides = spec => {
8
15
let onDemandSlides = [ ] ;
9
16
let startIndex = lazyStartIndex ( spec ) ;
@@ -316,7 +323,7 @@ export const keyHandler = (e, accessibility, rtl) => {
316
323
} ;
317
324
318
325
export const swipeStart = ( e , swipe , draggable ) => {
319
- e . target . tagName === "IMG" && e . preventDefault ( ) ;
326
+ e . target . tagName === "IMG" && safePreventDefault ( e ) ;
320
327
if ( ! swipe || ( ! draggable && e . type . indexOf ( "mouse" ) !== - 1 ) ) return "" ;
321
328
return {
322
329
dragging : true ,
@@ -352,8 +359,8 @@ export const swipeMove = (e, spec) => {
352
359
listWidth
353
360
} = spec ;
354
361
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 ) ;
357
364
let swipeLeft ,
358
365
state = { } ;
359
366
let curLeft = getTrackLeft ( spec ) ;
@@ -421,7 +428,7 @@ export const swipeMove = (e, spec) => {
421
428
}
422
429
if ( touchObject . swipeLength > 10 ) {
423
430
state [ "swiping" ] = true ;
424
- e . preventDefault ( ) ;
431
+ safePreventDefault ( e ) ;
425
432
}
426
433
return state ;
427
434
} ;
@@ -442,7 +449,7 @@ export const swipeEnd = (e, spec) => {
442
449
infinite
443
450
} = spec ;
444
451
if ( ! dragging ) {
445
- if ( swipe ) e . preventDefault ( ) ;
452
+ if ( swipe ) safePreventDefault ( e ) ;
446
453
return { } ;
447
454
}
448
455
let minSwipe = verticalSwiping
@@ -466,7 +473,7 @@ export const swipeEnd = (e, spec) => {
466
473
return state ;
467
474
}
468
475
if ( touchObject . swipeLength > minSwipe ) {
469
- e . preventDefault ( ) ;
476
+ safePreventDefault ( e ) ;
470
477
if ( onSwipe ) {
471
478
onSwipe ( swipeDirection ) ;
472
479
}
0 commit comments