@@ -30,7 +30,7 @@ import {
30
30
} from '@angular/core' ;
31
31
import { supportsPassiveEventListeners } from '@angular/cdk/platform' ;
32
32
import { Observable , Subject , Subscription , Observer } from 'rxjs' ;
33
- import { take } from 'rxjs/operators' ;
33
+ import { startWith , take } from 'rxjs/operators' ;
34
34
import { DragDropRegistry } from './drag-drop-registry' ;
35
35
import {
36
36
CdkDragDrop ,
@@ -270,7 +270,9 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
270
270
const rootElement = this . _rootElement = this . _getRootElement ( ) ;
271
271
rootElement . addEventListener ( 'mousedown' , this . _pointerDown , passiveEventListenerOptions ) ;
272
272
rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
273
- toggleNativeDragInteractions ( rootElement , false ) ;
273
+
274
+ this . _handles . changes . pipe ( startWith ( null ) ) . subscribe ( ( ) =>
275
+ toggleNativeDragInteractions ( rootElement , this . getChildHandles ( ) . length > 0 ) ) ;
274
276
} ) ;
275
277
}
276
278
@@ -301,10 +303,14 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
301
303
return this . _dragDropRegistry . isDragging ( this ) ;
302
304
}
303
305
306
+ /** Gets only handles that are not inside descendant `CdkDrag` instances. */
307
+ private getChildHandles ( ) {
308
+ return this . _handles . filter ( handle => handle . _parentDrag === this ) ;
309
+ }
310
+
304
311
/** Handler for the `mousedown`/`touchstart` events. */
305
312
_pointerDown = ( event : MouseEvent | TouchEvent ) => {
306
- // Skip handles inside descendant `CdkDrag` instances.
307
- const handles = this . _handles . filter ( handle => handle . _parentDrag === this ) ;
313
+ const handles = this . getChildHandles ( ) ;
308
314
309
315
// Delegate the event based on whether it started from a handle or the element itself.
310
316
if ( handles . length ) {
0 commit comments