File tree Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Expand file tree Collapse file tree 3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ ng_module(
14
14
"//src/cdk/platform" ,
15
15
"//src/cdk/overlay" ,
16
16
"//src/cdk/bidi" ,
17
+ "//src/cdk/coercion" ,
17
18
],
18
19
tsconfig = "//src/cdk:tsconfig-build.json" ,
19
20
)
Original file line number Diff line number Diff line change @@ -1151,6 +1151,36 @@ describe('CdkDrag', () => {
1151
1151
} ) ;
1152
1152
} ) ) ;
1153
1153
1154
+ it ( 'should be able to pass a single id to `connectedTo`' , fakeAsync ( ( ) => {
1155
+ const fixture = createComponent ( ConnectedDropZones ) ;
1156
+ fixture . detectChanges ( ) ;
1157
+
1158
+ const dropInstances = fixture . componentInstance . dropInstances . toArray ( ) ;
1159
+
1160
+ dropInstances [ 1 ] . id = 'done' ;
1161
+ dropInstances [ 0 ] . connectedTo = [ 'done' ] ;
1162
+ fixture . detectChanges ( ) ;
1163
+
1164
+ const groups = fixture . componentInstance . groupedDragItems ;
1165
+ const element = groups [ 0 ] [ 1 ] . element . nativeElement ;
1166
+ const targetRect = groups [ 1 ] [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
1167
+
1168
+ dragElementViaMouse ( fixture , element , targetRect . left + 1 , targetRect . top + 1 ) ;
1169
+ flush ( ) ;
1170
+ fixture . detectChanges ( ) ;
1171
+
1172
+ const event = fixture . componentInstance . droppedSpy . calls . mostRecent ( ) . args [ 0 ] ;
1173
+
1174
+ expect ( event ) . toBeTruthy ( ) ;
1175
+ expect ( event ) . toEqual ( {
1176
+ previousIndex : 1 ,
1177
+ currentIndex : 3 ,
1178
+ item : groups [ 0 ] [ 1 ] ,
1179
+ container : dropInstances [ 1 ] ,
1180
+ previousContainer : dropInstances [ 0 ]
1181
+ } ) ;
1182
+ } ) ) ;
1183
+
1154
1184
} ) ;
1155
1185
1156
1186
} ) ;
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
20
20
QueryList ,
21
21
ViewEncapsulation ,
22
22
} from '@angular/core' ;
23
+ import { coerceArray } from '@angular/cdk/coercion' ;
23
24
import { CdkDrag } from './drag' ;
24
25
import { CdkDragExit , CdkDragEnter , CdkDragDrop } from './drag-events' ;
25
26
import { CDK_DROP_CONTAINER } from './drop-container' ;
@@ -56,7 +57,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
56
57
* container's items can be transferred. Can either be references to other drop containers,
57
58
* or their unique IDs.
58
59
*/
59
- @Input ( ) connectedTo : ( CdkDrop | string ) [ ] = [ ] ;
60
+ @Input ( ) connectedTo : ( CdkDrop | string ) [ ] | CdkDrop | string = [ ] ;
60
61
61
62
/** Arbitrary data to attach to this container. */
62
63
@Input ( ) data : T ;
@@ -316,7 +317,7 @@ export class CdkDrop<T = any> implements OnInit, OnDestroy {
316
317
} )
317
318
. sort ( ( a , b ) => a . clientRect . top - b . clientRect . top ) ;
318
319
319
- this . _positionCache . siblings = this . connectedTo
320
+ this . _positionCache . siblings = coerceArray ( this . connectedTo )
320
321
. map ( drop => typeof drop === 'string' ? this . _dragDropRegistry . getDropContainer ( drop ) ! : drop )
321
322
. filter ( drop => drop && drop !== this )
322
323
. map ( drop => ( { drop, clientRect : drop . element . nativeElement . getBoundingClientRect ( ) } ) ) ;
You can’t perform that action at this time.
0 commit comments