File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
src/cdk/drag-drop/directives Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -5255,6 +5255,24 @@ describe('CdkDrag', () => {
5255
5255
} ) . not . toThrow ( ) ;
5256
5256
} ) ) ;
5257
5257
5258
+ it ( 'should warn when the connected container ID does not exist' , fakeAsync ( ( ) => {
5259
+ const fixture = createComponent ( ConnectedDropZones ) ;
5260
+ fixture . detectChanges ( ) ;
5261
+
5262
+ fixture . componentInstance . dropInstances . first . connectedTo = 'does-not-exist' ;
5263
+ fixture . detectChanges ( ) ;
5264
+
5265
+ const groups = fixture . componentInstance . groupedDragItems ;
5266
+ const element = groups [ 0 ] [ 1 ] . element . nativeElement ;
5267
+
5268
+ spyOn ( console , 'warn' ) ;
5269
+ dragElementViaMouse ( fixture , element , 0 , 0 ) ;
5270
+ flush ( ) ;
5271
+ fixture . detectChanges ( ) ;
5272
+
5273
+ expect ( console . warn ) . toHaveBeenCalledWith ( `CdkDropList could not find connected drop ` +
5274
+ `list with id "does-not-exist"` ) ;
5275
+ } ) ) ;
5258
5276
} ) ;
5259
5277
5260
5278
describe ( 'with nested drags' , ( ) => {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import {
19
19
SkipSelf ,
20
20
Inject ,
21
21
InjectionToken ,
22
+ isDevMode ,
22
23
} from '@angular/core' ;
23
24
import { Directionality } from '@angular/cdk/bidi' ;
24
25
import { ScrollDispatcher } from '@angular/cdk/scrolling' ;
@@ -252,8 +253,17 @@ export class CdkDropList<T = any> implements OnDestroy {
252
253
253
254
ref . beforeStarted . subscribe ( ( ) => {
254
255
const siblings = coerceArray ( this . connectedTo ) . map ( drop => {
255
- return typeof drop === 'string' ?
256
- CdkDropList . _dropLists . find ( list => list . id === drop ) ! : drop ;
256
+ if ( typeof drop === 'string' ) {
257
+ const correspondingDropList = CdkDropList . _dropLists . find ( list => list . id === drop ) ;
258
+
259
+ if ( ! correspondingDropList && isDevMode ( ) ) {
260
+ console . warn ( `CdkDropList could not find connected drop list with id "${ drop } "` ) ;
261
+ }
262
+
263
+ return correspondingDropList ! ;
264
+ }
265
+
266
+ return drop ;
257
267
} ) ;
258
268
259
269
if ( this . _group ) {
You can’t perform that action at this time.
0 commit comments