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