@@ -657,7 +657,8 @@ describe('CdkDrag', () => {
657
657
const initialRect = item . element . nativeElement . getBoundingClientRect ( ) ;
658
658
const targetRect = groups [ 1 ] [ 2 ] . element . nativeElement . getBoundingClientRect ( ) ;
659
659
660
- expect ( dropZones [ 0 ] . contains ( item . element . nativeElement ) ) . toBe ( true ) ;
660
+ expect ( dropZones [ 0 ] . contains ( item . element . nativeElement ) )
661
+ . toBe ( true , 'Expected placeholder to be inside the first container.' ) ;
661
662
dispatchMouseEvent ( item . element . nativeElement , 'mousedown' ) ;
662
663
fixture . detectChanges ( ) ;
663
664
@@ -675,7 +676,7 @@ describe('CdkDrag', () => {
675
676
fixture . detectChanges ( ) ;
676
677
677
678
expect ( dropZones [ 0 ] . contains ( placeholder ) )
678
- . toBe ( true , 'Expected placeholder to be inside first container.' ) ;
679
+ . toBe ( true , 'Expected placeholder to be back inside first container.' ) ;
679
680
680
681
dispatchMouseEvent ( document , 'mouseup' ) ;
681
682
fixture . detectChanges ( ) ;
@@ -746,6 +747,46 @@ describe('CdkDrag', () => {
746
747
assertDownwardSorting ( fixture , Array . from ( dropZones [ 1 ] . querySelectorAll ( '.cdk-drag' ) ) ) ;
747
748
} ) ) ;
748
749
750
+ it ( 'should be able to return the last item inside its initial container' , fakeAsync ( ( ) => {
751
+ const fixture = createComponent ( ConnectedDropZones ) ;
752
+
753
+ // Make sure there's only one item in the first list.
754
+ fixture . componentInstance . todo = [ 'things' ] ;
755
+ fixture . detectChanges ( ) ;
756
+
757
+ const groups = fixture . componentInstance . groupedDragItems ;
758
+ const dropZones = fixture . componentInstance . dropInstances . map ( d => d . element . nativeElement ) ;
759
+ const item = groups [ 0 ] [ 0 ] ;
760
+ const initialRect = item . element . nativeElement . getBoundingClientRect ( ) ;
761
+ const targetRect = groups [ 1 ] [ 0 ] . element . nativeElement . getBoundingClientRect ( ) ;
762
+
763
+ expect ( dropZones [ 0 ] . contains ( item . element . nativeElement ) )
764
+ . toBe ( true , 'Expected placeholder to be inside the first container.' ) ;
765
+ dispatchMouseEvent ( item . element . nativeElement , 'mousedown' ) ;
766
+ fixture . detectChanges ( ) ;
767
+
768
+ const placeholder = dropZones [ 0 ] . querySelector ( '.cdk-drag-placeholder' ) ! ;
769
+
770
+ expect ( placeholder ) . toBeTruthy ( ) ;
771
+
772
+ dispatchMouseEvent ( document , 'mousemove' , targetRect . left + 1 , targetRect . top + 1 ) ;
773
+ fixture . detectChanges ( ) ;
774
+
775
+ expect ( dropZones [ 1 ] . contains ( placeholder ) )
776
+ . toBe ( true , 'Expected placeholder to be inside second container.' ) ;
777
+
778
+ dispatchMouseEvent ( document , 'mousemove' , initialRect . left + 1 , initialRect . top + 1 ) ;
779
+ fixture . detectChanges ( ) ;
780
+
781
+ expect ( dropZones [ 0 ] . contains ( placeholder ) )
782
+ . toBe ( true , 'Expected placeholder to be back inside first container.' ) ;
783
+
784
+ dispatchMouseEvent ( document , 'mouseup' ) ;
785
+ fixture . detectChanges ( ) ;
786
+
787
+ expect ( fixture . componentInstance . droppedSpy ) . not . toHaveBeenCalled ( ) ;
788
+ } ) ) ;
789
+
749
790
} ) ;
750
791
751
792
} ) ;
@@ -916,29 +957,36 @@ export class DraggableInDropZoneWithCustomPlaceholder {
916
957
917
958
918
959
@Component ( {
960
+ encapsulation : ViewEncapsulation . None ,
961
+ styles : [ `
962
+ .cdk-drop {
963
+ display: block;
964
+ width: 100px;
965
+ min-height: ${ ITEM_HEIGHT } px;
966
+ background: hotpink;
967
+ }
968
+
969
+ .cdk-drag {
970
+ display: block;
971
+ height: ${ ITEM_HEIGHT } px;
972
+ background: red;
973
+ }
974
+ ` ] ,
919
975
template : `
920
976
<cdk-drop
921
977
#todoZone
922
- style="display: block; width: 100px; background: pink;"
923
978
[data]="todo"
924
979
[connectedTo]="[doneZone]"
925
980
(dropped)="droppedSpy($event)">
926
- <div
927
- *ngFor="let item of todo"
928
- cdkDrag
929
- style="width: 100%; height: ${ ITEM_HEIGHT } px; background: red;">{{item}}</div>
981
+ <div *ngFor="let item of todo" cdkDrag>{{item}}</div>
930
982
</cdk-drop>
931
983
932
984
<cdk-drop
933
985
#doneZone
934
- style="display: block; width: 100px; background: purple;"
935
986
[data]="done"
936
987
[connectedTo]="[todoZone]"
937
988
(dropped)="droppedSpy($event)">
938
- <div
939
- *ngFor="let item of done"
940
- cdkDrag
941
- style="width: 100%; height: ${ ITEM_HEIGHT } px; background: green;">{{item}}</div>
989
+ <div *ngFor="let item of done" cdkDrag>{{item}}</div>
942
990
</cdk-drop>
943
991
`
944
992
} )
0 commit comments