@@ -2720,6 +2720,21 @@ describe('CdkDrag', () => {
2720
2720
expect ( preview . style . transform ) . toBe ( 'translate3d(100px, 50px, 0px)' ) ;
2721
2721
} ) ) ;
2722
2722
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
+
2723
2738
it ( 'should be able to customize the placeholder' , fakeAsync ( ( ) => {
2724
2739
const fixture = createComponent ( DraggableInDropZoneWithCustomPlaceholder ) ;
2725
2740
fixture . detectChanges ( ) ;
@@ -2753,6 +2768,21 @@ describe('CdkDrag', () => {
2753
2768
expect ( placeholder . textContent ! . trim ( ) ) . not . toContain ( 'Custom placeholder' ) ;
2754
2769
} ) ) ;
2755
2770
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
+
2756
2786
it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
2757
2787
const fixture = createComponent ( DraggableInDropZone ) ;
2758
2788
fixture . detectChanges ( ) ;
@@ -4497,6 +4527,28 @@ class DraggableInDropZoneWithCustomPreview {
4497
4527
}
4498
4528
4499
4529
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
+
4500
4552
@Component ( {
4501
4553
template : `
4502
4554
<div cdkDropList style="width: 100px; background: pink;">
@@ -4516,6 +4568,22 @@ class DraggableInDropZoneWithCustomPlaceholder {
4516
4568
renderPlaceholder = true ;
4517
4569
}
4518
4570
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
+
4519
4587
const CONNECTED_DROP_ZONES_STYLES = [ `
4520
4588
.cdk-drop-list {
4521
4589
display: block;
0 commit comments