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 @@ -5280,6 +5280,24 @@ describe('CdkDrag', () => {
5280
5280
} ) . not . toThrow ( ) ;
5281
5281
} ) ) ;
5282
5282
5283
+ it ( 'should warn when the connected container ID does not exist' , fakeAsync ( ( ) => {
5284
+ const fixture = createComponent ( ConnectedDropZones ) ;
5285
+ fixture . detectChanges ( ) ;
5286
+
5287
+ fixture . componentInstance . dropInstances . first . connectedTo = 'does-not-exist' ;
5288
+ fixture . detectChanges ( ) ;
5289
+
5290
+ const groups = fixture . componentInstance . groupedDragItems ;
5291
+ const element = groups [ 0 ] [ 1 ] . element . nativeElement ;
5292
+
5293
+ spyOn ( console , 'warn' ) ;
5294
+ dragElementViaMouse ( fixture , element , 0 , 0 ) ;
5295
+ flush ( ) ;
5296
+ fixture . detectChanges ( ) ;
5297
+
5298
+ expect ( console . warn ) . toHaveBeenCalledWith ( `CdkDropList could not find connected drop ` +
5299
+ `list with id "does-not-exist"` ) ;
5300
+ } ) ) ;
5283
5301
} ) ;
5284
5302
5285
5303
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