@@ -2720,6 +2720,21 @@ describe('CdkDrag', () => {
27202720 expect ( preview . style . transform ) . toBe ( 'translate3d(100px, 50px, 0px)' ) ;
27212721 } ) ) ;
27222722
2723+ it ( 'should not throw when custom preview only has text' , fakeAsync ( ( ) => {
2724+ const fixture = createComponent ( DraggableInDropZoneWithCustomTextOnlyPreview ) ;
2725+ fixture . detectChanges ( ) ;
2726+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2727+
2728+ expect ( ( ) => {
2729+ startDraggingViaMouse ( fixture , item ) ;
2730+ } ) . not . toThrow ( ) ;
2731+
2732+ const preview = document . querySelector ( '.cdk-drag-preview' ) ! as HTMLElement ;
2733+
2734+ expect ( preview ) . toBeTruthy ( ) ;
2735+ expect ( preview . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
2736+ } ) ) ;
2737+
27232738 it ( 'should be able to customize the placeholder' , fakeAsync ( ( ) => {
27242739 const fixture = createComponent ( DraggableInDropZoneWithCustomPlaceholder ) ;
27252740 fixture . detectChanges ( ) ;
@@ -2753,6 +2768,21 @@ describe('CdkDrag', () => {
27532768 expect ( placeholder . textContent ! . trim ( ) ) . not . toContain ( 'Custom placeholder' ) ;
27542769 } ) ) ;
27552770
2771+ it ( 'should not throw when custom placeholder only has text' , fakeAsync ( ( ) => {
2772+ const fixture = createComponent ( DraggableInDropZoneWithCustomTextOnlyPlaceholder ) ;
2773+ fixture . detectChanges ( ) ;
2774+ const item = fixture . componentInstance . dragItems . toArray ( ) [ 1 ] . element . nativeElement ;
2775+
2776+ expect ( ( ) => {
2777+ startDraggingViaMouse ( fixture , item ) ;
2778+ } ) . not . toThrow ( ) ;
2779+
2780+ const placeholder = document . querySelector ( '.cdk-drag-placeholder' ) ! as HTMLElement ;
2781+
2782+ expect ( placeholder ) . toBeTruthy ( ) ;
2783+ expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Hello One' ) ;
2784+ } ) ) ;
2785+
27562786 it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
27572787 const fixture = createComponent ( DraggableInDropZone ) ;
27582788 fixture . detectChanges ( ) ;
@@ -4497,6 +4527,28 @@ class DraggableInDropZoneWithCustomPreview {
44974527}
44984528
44994529
4530+ @Component ( {
4531+ template : `
4532+ <div cdkDropList style="width: 100px; background: pink;">
4533+ <div
4534+ *ngFor="let item of items"
4535+ cdkDrag
4536+ [cdkDragConstrainPosition]="constrainPosition"
4537+ [cdkDragBoundary]="boundarySelector"
4538+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
4539+ {{item}}
4540+ <ng-template cdkDragPreview>Hello {{item}}</ng-template>
4541+ </div>
4542+ </div>
4543+ `
4544+ } )
4545+ class DraggableInDropZoneWithCustomTextOnlyPreview {
4546+ @ViewChild ( CdkDropList , { static : false } ) dropInstance : CdkDropList ;
4547+ @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
4548+ items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
4549+ }
4550+
4551+
45004552@Component ( {
45014553 template : `
45024554 <div cdkDropList style="width: 100px; background: pink;">
@@ -4516,6 +4568,22 @@ class DraggableInDropZoneWithCustomPlaceholder {
45164568 renderPlaceholder = true ;
45174569}
45184570
4571+ @Component ( {
4572+ template : `
4573+ <div cdkDropList style="width: 100px; background: pink;">
4574+ <div *ngFor="let item of items" cdkDrag
4575+ style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">
4576+ {{item}}
4577+ <ng-template cdkDragPlaceholder>Hello {{item}}</ng-template>
4578+ </div>
4579+ </div>
4580+ `
4581+ } )
4582+ class DraggableInDropZoneWithCustomTextOnlyPlaceholder {
4583+ @ViewChildren ( CdkDrag ) dragItems : QueryList < CdkDrag > ;
4584+ items = [ 'Zero' , 'One' , 'Two' , 'Three' ] ;
4585+ }
4586+
45194587const CONNECTED_DROP_ZONES_STYLES = [ `
45204588 .cdk-drop-list {
45214589 display: block;
0 commit comments