File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -493,6 +493,7 @@ describe('CdkDrag', () => {
493
493
expect ( dragElement . style . touchAction )
494
494
. not . toEqual ( 'none' , 'should not disable touchAction on when there is a drag handle' ) ;
495
495
} ) ;
496
+
496
497
it ( 'should be able to reset a freely-dragged item to its initial position' , fakeAsync ( ( ) => {
497
498
const fixture = createComponent ( StandaloneDraggable ) ;
498
499
fixture . detectChanges ( ) ;
@@ -545,7 +546,14 @@ describe('CdkDrag', () => {
545
546
expect ( fixture . componentInstance . endedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
546
547
} ) ) ;
547
548
548
- } ) ;
549
+ it ( 'should throw if attached to an ng-container' , fakeAsync ( ( ) => {
550
+ expect ( ( ) => {
551
+ createComponent ( DraggableOnNgContainer ) . detectChanges ( ) ;
552
+ flush ( ) ;
553
+ } ) . toThrowError ( / ^ c d k D r a g m u s t b e a t t a c h e d t o a n e l e m e n t n o d e / ) ;
554
+ } ) ) ;
555
+
556
+ } ) ;
549
557
550
558
describe ( 'draggable with a handle' , ( ) => {
551
559
it ( 'should not be able to drag the entire element if it has a handle' , fakeAsync ( ( ) => {
@@ -2580,6 +2588,14 @@ class ConnectedDropZonesWithSingleItems {
2580
2588
droppedSpy = jasmine . createSpy ( 'dropped spy' ) ;
2581
2589
}
2582
2590
2591
+ @Component ( {
2592
+ template : `
2593
+ <ng-container cdkDrag></ng-container>
2594
+ `
2595
+ } )
2596
+ class DraggableOnNgContainer { }
2597
+
2598
+
2583
2599
/**
2584
2600
* Component that passes through whatever content is projected into it.
2585
2601
* Used to test having drag elements being projected into a component.
Original file line number Diff line number Diff line change @@ -307,6 +307,12 @@ export class CdkDrag<T = any> implements AfterViewInit, OnDestroy {
307
307
. pipe ( take ( 1 ) )
308
308
. subscribe ( ( ) => {
309
309
const rootElement = this . _rootElement = this . _getRootElement ( ) ;
310
+
311
+ if ( rootElement . nodeType !== this . _document . ELEMENT_NODE ) {
312
+ throw Error ( `cdkDrag must be attached to an element node. ` +
313
+ `Currently attached to "${ rootElement . nodeName } ".` ) ;
314
+ }
315
+
310
316
rootElement . addEventListener ( 'mousedown' , this . _pointerDown , activeEventListenerOptions ) ;
311
317
rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
312
318
this . _handles . changes . pipe ( startWith ( null ) ) . subscribe ( ( ) =>
You can’t perform that action at this time.
0 commit comments