@@ -1776,6 +1776,23 @@ describe('CdkDrag', () => {
17761776 expect ( preview . textContent ! . trim ( ) ) . toContain ( 'Custom preview' ) ;
17771777 } ) ) ;
17781778
1779+ it ( 'should handle the custom preview being removed' , fakeAsync ( ( ) => {
1780+ const fixture = createComponent ( DraggableInDropZoneWithCustomPreview ) ;
1781+ fixture . detectChanges ( ) ;
1782+ flush ( ) ;
1783+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1784+
1785+ fixture . componentInstance . renderCustomPreview = false ;
1786+ fixture . detectChanges ( ) ;
1787+ startDraggingViaMouse ( fixture , item ) ;
1788+
1789+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
1790+
1791+ expect ( preview ) . toBeTruthy ( ) ;
1792+ expect ( preview . classList ) . not . toContain ( 'custom-preview' ) ;
1793+ expect ( preview . textContent ! . trim ( ) ) . not . toContain ( 'Custom preview' ) ;
1794+ } ) ) ;
1795+
17791796 it ( 'should be able to constrain the position of a custom preview' , fakeAsync ( ( ) => {
17801797 const fixture = createComponent ( DraggableInDropZoneWithCustomPreview ) ;
17811798 fixture . componentInstance . boundarySelector = '.cdk-drop-list' ;
@@ -1900,6 +1917,25 @@ describe('CdkDrag', () => {
19001917 expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Custom placeholder' ) ;
19011918 } ) ) ;
19021919
1920+ it ( 'should handle the custom placeholder being removed' , fakeAsync ( ( ) => {
1921+ const fixture = createComponent ( DraggableInDropZoneWithCustomPlaceholder ) ;
1922+ fixture . detectChanges ( ) ;
1923+ flush ( ) ;
1924+
1925+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
1926+
1927+ fixture . componentInstance . renderPlaceholder = false ;
1928+ fixture . detectChanges ( ) ;
1929+
1930+ startDraggingViaMouse ( fixture , item ) ;
1931+
1932+ const placeholder = document . querySelector ( '.cdk-drag-placeholder' ) ! as HTMLElement ;
1933+
1934+ expect ( placeholder ) . toBeTruthy ( ) ;
1935+ expect ( placeholder . classList ) . not . toContain ( 'custom-placeholder' ) ;
1936+ expect ( placeholder . textContent ! . trim ( ) ) . not . toContain ( 'Custom placeholder' ) ;
1937+ } ) ) ;
1938+
19031939 it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
19041940 const fixture = createComponent ( DraggableInDropZone ) ;
19051941 fixture . detectChanges ( ) ;
@@ -2713,10 +2749,13 @@ class DraggableInHorizontalDropZone {
27132749 [cdkDragBoundary]="boundarySelector"
27142750 style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
27152751 {{item}}
2716- <div
2717- class="custom-preview"
2718- style="width: 50px; height: 50px; background: purple;"
2719- *cdkDragPreview>Custom preview</div>
2752+
2753+ <ng-container *ngIf="renderCustomPreview">
2754+ <div
2755+ class="custom-preview"
2756+ style="width: 50px; height: 50px; background: purple;"
2757+ *cdkDragPreview>Custom preview</div>
2758+ </ng-container>
27202759 </div>
27212760 </div>
27222761 `
@@ -2726,6 +2765,7 @@ class DraggableInDropZoneWithCustomPreview {
27262765 @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
27272766 items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
27282767 boundarySelector : string ;
2768+ renderCustomPreview = true ;
27292769}
27302770
27312771
@@ -2735,14 +2775,17 @@ class DraggableInDropZoneWithCustomPreview {
27352775 <div *ngFor="let item of items" cdkDrag
27362776 style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
27372777 {{item}}
2738- <div class="custom-placeholder" *cdkDragPlaceholder>Custom placeholder</div>
2778+ <ng-container *ngIf="renderPlaceholder">
2779+ <div class="custom-placeholder" *cdkDragPlaceholder>Custom placeholder</div>
2780+ </ng-container>
27392781 </div>
27402782 </div>
27412783 `
27422784} )
27432785class DraggableInDropZoneWithCustomPlaceholder {
27442786 @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
27452787 items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
2788+ renderPlaceholder = true ;
27462789}
27472790
27482791
0 commit comments