@@ -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,10 @@ 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 ) )
275
+ . subscribe ( ( ) =>
276
+ toggleNativeDragInteractions ( rootElement , this . getChildHandles ( ) . length > 0 ) ) ;
274
277
} ) ;
275
278
}
276
279
@@ -301,10 +304,14 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
301
304
return this . _dragDropRegistry . isDragging ( this ) ;
302
305
}
303
306
307
+ /** Gets only handles that are not inside descendant `CdkDrag` instances. */
308
+ private getChildHandles ( ) {
309
+ return this . _handles . filter ( handle => handle . _parentDrag === this ) ;
310
+ }
311
+
304
312
/** Handler for the `mousedown`/`touchstart` events. */
305
313
_pointerDown = ( event : MouseEvent | TouchEvent ) => {
306
- // Skip handles inside descendant `CdkDrag` instances.
307
- const handles = this . _handles . filter ( handle => handle . _parentDrag === this ) ;
314
+ const handles = this . getChildHandles ( ) ;
308
315
309
316
// Delegate the event based on whether it started from a handle or the element itself.
310
317
if ( handles . length ) {
0 commit comments