@@ -2995,6 +2995,21 @@ describe('CdkDrag', () => {
2995
2995
expect ( preview . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
2996
2996
} ) ) ;
2997
2997
2998
+ it ( 'should handle custom preview with multiple root nodes' , fakeAsync ( ( ) => {
2999
+ const fixture = createComponent ( DraggableInDropZoneWithCustomMultiNodePreview ) ;
3000
+ fixture . detectChanges ( ) ;
3001
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
3002
+
3003
+ expect ( ( ) => {
3004
+ startDraggingViaMouse ( fixture , item ) ;
3005
+ } ) . not . toThrow ( ) ;
3006
+
3007
+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
3008
+
3009
+ expect ( preview ) . toBeTruthy ( ) ;
3010
+ expect ( preview . textContent ! . trim ( ) ) . toContain ( 'HelloOne' ) ;
3011
+ } ) ) ;
3012
+
2998
3013
it ( 'should be able to customize the placeholder' , fakeAsync ( ( ) => {
2999
3014
const fixture = createComponent ( DraggableInDropZoneWithCustomPlaceholder ) ;
3000
3015
fixture . detectChanges ( ) ;
@@ -3067,6 +3082,21 @@ describe('CdkDrag', () => {
3067
3082
expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
3068
3083
} ) ) ;
3069
3084
3085
+ it ( 'should handle custom placeholder with multiple root nodes' , fakeAsync ( ( ) => {
3086
+ const fixture = createComponent ( DraggableInDropZoneWithCustomMultiNodePlaceholder ) ;
3087
+ fixture . detectChanges ( ) ;
3088
+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
3089
+
3090
+ expect ( ( ) => {
3091
+ startDraggingViaMouse ( fixture , item ) ;
3092
+ } ) . not . toThrow ( ) ;
3093
+
3094
+ const placeholder = document . querySelector ( '.cdk-drag-placeholder' ) ! as HTMLElement ;
3095
+
3096
+ expect ( placeholder ) . toBeTruthy ( ) ;
3097
+ expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'HelloOne' ) ;
3098
+ } ) ) ;
3099
+
3070
3100
it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
3071
3101
const fixture = createComponent ( DraggableInDropZone ) ;
3072
3102
fixture . detectChanges ( ) ;
@@ -5209,6 +5239,28 @@ class DraggableInDropZoneWithCustomTextOnlyPreview {
5209
5239
}
5210
5240
5211
5241
5242
+ @Component ( {
5243
+ template : `
5244
+ <div cdkDropList style="width: 100px; background: pink;">
5245
+ <div
5246
+ *ngFor="let item of items"
5247
+ cdkDrag
5248
+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
5249
+ {{item}}
5250
+ <ng-template cdkDragPreview>
5251
+ <span>Hello</span>
5252
+ <span>{{item}}</span>
5253
+ </ng-template>
5254
+ </div>
5255
+ </div>
5256
+ `
5257
+ } )
5258
+ class DraggableInDropZoneWithCustomMultiNodePreview {
5259
+ @ViewChild ( CdkDropList ) dropInstance : CdkDropList ;
5260
+ @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
5261
+ items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
5262
+ }
5263
+
5212
5264
@Component ( {
5213
5265
template : `
5214
5266
<div
@@ -5257,6 +5309,25 @@ class DraggableInDropZoneWithCustomTextOnlyPlaceholder {
5257
5309
items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
5258
5310
}
5259
5311
5312
+ @Component ( {
5313
+ template : `
5314
+ <div cdkDropList style="width: 100px; background: pink;">
5315
+ <div *ngFor="let item of items" cdkDrag
5316
+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
5317
+ {{item}}
5318
+ <ng-template cdkDragPlaceholder>
5319
+ <span>Hello</span>
5320
+ <span>{{item}}</span>
5321
+ </ng-template>
5322
+ </div>
5323
+ </div>
5324
+ `
5325
+ } )
5326
+ class DraggableInDropZoneWithCustomMultiNodePlaceholder {
5327
+ @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
5328
+ items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
5329
+ }
5330
+
5260
5331
const CONNECTED_DROP_ZONES_STYLES = [ `
5261
5332
.cdk-drop-list {
5262
5333
display: block;
0 commit comments