@@ -2995,6 +2995,21 @@ describe('CdkDrag', () => {
29952995 expect ( preview . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
29962996 } ) ) ;
29972997
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+
29983013 it ( 'should be able to customize the placeholder' , fakeAsync ( ( ) => {
29993014 const fixture = createComponent ( DraggableInDropZoneWithCustomPlaceholder ) ;
30003015 fixture . detectChanges ( ) ;
@@ -3067,6 +3082,21 @@ describe('CdkDrag', () => {
30673082 expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
30683083 } ) ) ;
30693084
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+
30703100 it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
30713101 const fixture = createComponent ( DraggableInDropZone ) ;
30723102 fixture . detectChanges ( ) ;
@@ -5209,6 +5239,28 @@ class DraggableInDropZoneWithCustomTextOnlyPreview {
52095239}
52105240
52115241
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+
52125264@Component ( {
52135265 template : `
52145266 <div
@@ -5257,6 +5309,25 @@ class DraggableInDropZoneWithCustomTextOnlyPlaceholder {
52575309 items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
52585310}
52595311
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+
52605331const CONNECTED_DROP_ZONES_STYLES = [ `
52615332 .cdk-drop-list {
52625333 display: block;
0 commit comments