File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -504,6 +504,7 @@ describe('CdkDrag', () => {
504504 expect ( dragElement . style . touchAction )
505505 . not . toEqual ( 'none' , 'should not disable touchAction on when there is a drag handle' ) ;
506506 } ) ;
507+
507508 it ( 'should be able to reset a freely-dragged item to its initial position' , fakeAsync ( ( ) => {
508509 const fixture = createComponent ( StandaloneDraggable ) ;
509510 fixture . detectChanges ( ) ;
@@ -556,7 +557,14 @@ describe('CdkDrag', () => {
556557 expect ( fixture . componentInstance . endedSpy ) . toHaveBeenCalledTimes ( 1 ) ;
557558 } ) ) ;
558559
559- } ) ;
560+ it ( 'should throw if attached to an ng-container' , fakeAsync ( ( ) => {
561+ expect ( ( ) => {
562+ createComponent ( DraggableOnNgContainer ) . detectChanges ( ) ;
563+ flush ( ) ;
564+ } ) . 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 / ) ;
565+ } ) ) ;
566+
567+ } ) ;
560568
561569 describe ( 'draggable with a handle' , ( ) => {
562570 it ( 'should not be able to drag the entire element if it has a handle' , fakeAsync ( ( ) => {
@@ -2631,6 +2639,15 @@ class NestedDropListGroups {
26312639}
26322640
26332641
2642+ @Component ( {
2643+ template : `
2644+ <ng-container cdkDrag></ng-container>
2645+ `
2646+ } )
2647+ class DraggableOnNgContainer { }
2648+
2649+
2650+
26342651/**
26352652 * Component that passes through whatever content is projected into it.
26362653 * 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 {
307307 . pipe ( take ( 1 ) )
308308 . subscribe ( ( ) => {
309309 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+
310316 rootElement . addEventListener ( 'mousedown' , this . _pointerDown , activeEventListenerOptions ) ;
311317 rootElement . addEventListener ( 'touchstart' , this . _pointerDown , passiveEventListenerOptions ) ;
312318 this . _handles . changes . pipe ( startWith ( null ) ) . subscribe ( ( ) =>
You can’t perform that action at this time.
0 commit comments