@@ -28,6 +28,7 @@ import {
28
28
SkipSelf ,
29
29
ViewContainerRef ,
30
30
} from '@angular/core' ;
31
+ import { supportsPassiveEventListeners } from '@angular/cdk/platform' ;
31
32
import { Observable , Subject , Subscription , Observer } from 'rxjs' ;
32
33
import { take } from 'rxjs/operators' ;
33
34
import { DragDropRegistry } from './drag-drop-registry' ;
@@ -77,6 +78,10 @@ export function CDK_DRAG_CONFIG_FACTORY(): CdkDragConfig {
77
78
return { dragStartThreshold : 5 , pointerDirectionChangeThreshold : 5 } ;
78
79
}
79
80
81
+ /** Options that can be used to bind a passive event listener. */
82
+ const passiveEventListenerOptions = supportsPassiveEventListeners ( ) ?
83
+ { passive : true } as EventListenerOptions : false ;
84
+
80
85
/** Element that can be moved inside a CdkDropList container. */
81
86
@Directive ( {
82
87
selector : '[cdkDrag]' ,
@@ -255,15 +260,17 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
255
260
// their original DOM position and then they get transferred to the portal.
256
261
this . _ngZone . onStable . asObservable ( ) . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
257
262
const rootElement = this . _rootElement = this . _getRootElement ( ) ;
258
- rootElement . addEventListener ( 'mousedown' , this . _pointerDown ) ;
259
- rootElement . addEventListener ( 'touchstart' , this . _pointerDown ) ;
263
+ rootElement . addEventListener ( 'mousedown' , this . _pointerDown , passiveEventListenerOptions ) ;
264
+ rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
260
265
toggleNativeDragInteractions ( rootElement , false ) ;
261
266
} ) ;
262
267
}
263
268
264
269
ngOnDestroy ( ) {
265
- this . _rootElement . removeEventListener ( 'mousedown' , this . _pointerDown ) ;
266
- this . _rootElement . removeEventListener ( 'touchstart' , this . _pointerDown ) ;
270
+ this . _rootElement . removeEventListener ( 'mousedown' , this . _pointerDown ,
271
+ passiveEventListenerOptions ) ;
272
+ this . _rootElement . removeEventListener ( 'touchstart' , this . _pointerDown ,
273
+ passiveEventListenerOptions ) ;
267
274
this . _destroyPreview ( ) ;
268
275
this . _destroyPlaceholder ( ) ;
269
276
0 commit comments