@@ -2978,6 +2978,21 @@ describe('CdkDrag', () => {
2978
2978
expect ( preview . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
2979
2979
} ) ) ;
2980
2980
2981
+ it ( 'should handle custom preview with multiple root nodes' , fakeAsync ( ( ) => {
2982
+ const fixture = createComponent ( DraggableInDropZoneWithCustomMultiNodePreview ) ;
2983
+ fixture . detectChanges ( ) ;
2984
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2985
+
2986
+ expect ( ( ) => {
2987
+ startDraggingViaMouse ( fixture , item ) ;
2988
+ } ) . not . toThrow ( ) ;
2989
+
2990
+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
2991
+
2992
+ expect ( preview ) . toBeTruthy ( ) ;
2993
+ expect ( preview . textContent ! . trim ( ) ) . toContain ( 'HelloOne' ) ;
2994
+ } ) ) ;
2995
+
2981
2996
it ( 'should be able to customize the placeholder' , fakeAsync ( ( ) => {
2982
2997
const fixture = createComponent ( DraggableInDropZoneWithCustomPlaceholder ) ;
2983
2998
fixture . detectChanges ( ) ;
@@ -3050,6 +3065,21 @@ describe('CdkDrag', () => {
3050
3065
expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
3051
3066
} ) ) ;
3052
3067
3068
+ it ( 'should handle custom placeholder with multiple root nodes' , fakeAsync ( ( ) => {
3069
+ const fixture = createComponent ( DraggableInDropZoneWithCustomMultiNodePlaceholder ) ;
3070
+ fixture . detectChanges ( ) ;
3071
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
3072
+
3073
+ expect ( ( ) => {
3074
+ startDraggingViaMouse ( fixture , item ) ;
3075
+ } ) . not . toThrow ( ) ;
3076
+
3077
+ const placeholder = document . querySelector ( '.cdk-drag-placeholder' ) ! as HTMLElement ;
3078
+
3079
+ expect ( placeholder ) . toBeTruthy ( ) ;
3080
+ expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'HelloOne' ) ;
3081
+ } ) ) ;
3082
+
3053
3083
it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
3054
3084
const fixture = createComponent ( DraggableInDropZone ) ;
3055
3085
fixture . detectChanges ( ) ;
@@ -5192,6 +5222,28 @@ class DraggableInDropZoneWithCustomTextOnlyPreview {
5192
5222
}
5193
5223
5194
5224
5225
+ @Component ( {
5226
+ template : `
5227
+ <div cdkDropList style="width: 100px; background: pink;">
5228
+ <div
5229
+ *ngFor="let item of items"
5230
+ cdkDrag
5231
+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
5232
+ {{item}}
5233
+ <ng-template cdkDragPreview>
5234
+ <span>Hello</span>
5235
+ <span>{{item}}</span>
5236
+ </ng-template>
5237
+ </div>
5238
+ </div>
5239
+ `
5240
+ } )
5241
+ class DraggableInDropZoneWithCustomMultiNodePreview {
5242
+ @ViewChild ( CdkDropList ) dropInstance : CdkDropList ;
5243
+ @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
5244
+ items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
5245
+ }
5246
+
5195
5247
@Component ( {
5196
5248
template : `
5197
5249
<div
@@ -5240,6 +5292,25 @@ class DraggableInDropZoneWithCustomTextOnlyPlaceholder {
5240
5292
items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
5241
5293
}
5242
5294
5295
+ @Component ( {
5296
+ template : `
5297
+ <div cdkDropList style="width: 100px; background: pink;">
5298
+ <div *ngFor="let item of items" cdkDrag
5299
+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
5300
+ {{item}}
5301
+ <ng-template cdkDragPlaceholder>
5302
+ <span>Hello</span>
5303
+ <span>{{item}}</span>
5304
+ </ng-template>
5305
+ </div>
5306
+ </div>
5307
+ `
5308
+ } )
5309
+ class DraggableInDropZoneWithCustomMultiNodePlaceholder {
5310
+ @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
5311
+ items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
5312
+ }
5313
+
5243
5314
const CONNECTED_DROP_ZONES_STYLES = [ `
5244
5315
.cdk-drop-list {
5245
5316
display: block;
0 commit comments