@@ -562,7 +562,7 @@ describe('CdkDrag', () => {
562
562
// Add a few pixels to the left offset so we get some overlap.
563
563
dispatchMouseEvent ( document , 'mousemove' , elementRect . left + 5 , elementRect . top ) ;
564
564
fixture . detectChanges ( ) ;
565
- expect ( getElementIndex ( placeholder ) ) . toBe ( i ) ;
565
+ expect ( getElementIndexByPosition ( placeholder , 'left' ) ) . toBe ( i ) ;
566
566
}
567
567
568
568
dispatchMouseEvent ( document , 'mouseup' ) ;
@@ -590,7 +590,7 @@ describe('CdkDrag', () => {
590
590
// Remove a few pixels from the right offset so we get some overlap.
591
591
dispatchMouseEvent ( document , 'mousemove' , elementRect . right - 5 , elementRect . top ) ;
592
592
fixture . detectChanges ( ) ;
593
- expect ( getElementIndex ( placeholder ) ) . toBe ( Math . min ( i + 1 , items . length - 1 ) ) ;
593
+ expect ( getElementIndexByPosition ( placeholder , 'left' ) ) . toBe ( i ) ;
594
594
}
595
595
596
596
dispatchMouseEvent ( document , 'mouseup' ) ;
@@ -660,6 +660,31 @@ describe('CdkDrag', () => {
660
660
expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Custom placeholder' ) ;
661
661
} ) ) ;
662
662
663
+ it ( 'should clear the `transform` value from siblings when item is dropped`' , fakeAsync ( ( ) => {
664
+ const fixture = createComponent ( DraggableInDropZone ) ;
665
+ fixture . detectChanges ( ) ;
666
+
667
+ const dragItems = fixture . componentInstance . dragItems ;
668
+ const firstItem = dragItems . first ;
669
+ const thirdItem = dragItems . toArray ( ) [ 2 ] . element . nativeElement ;
670
+ const thirdItemRect = thirdItem . getBoundingClientRect ( ) ;
671
+
672
+ dispatchMouseEvent ( firstItem . element . nativeElement , 'mousedown' ) ;
673
+ fixture . detectChanges ( ) ;
674
+
675
+ dispatchMouseEvent ( document , 'mousemove' , thirdItemRect . left + 1 , thirdItemRect . top + 1 ) ;
676
+ fixture . detectChanges ( ) ;
677
+
678
+ expect ( thirdItem . style . transform ) . toBeTruthy ( ) ;
679
+
680
+ dispatchMouseEvent ( document , 'mouseup' ) ;
681
+ fixture . detectChanges ( ) ;
682
+ flush ( ) ;
683
+ fixture . detectChanges ( ) ;
684
+
685
+ expect ( thirdItem . style . transform ) . toBeFalsy ( ) ;
686
+ } ) ) ;
687
+
663
688
} ) ;
664
689
665
690
describe ( 'in a connected drop container' , ( ) => {
@@ -1151,9 +1176,15 @@ function dragElementViaTouch(fixture: ComponentFixture<any>,
1151
1176
fixture . detectChanges ( ) ;
1152
1177
}
1153
1178
1154
- /** Gets the index of a DOM element inside its parent. */
1155
- function getElementIndex ( element : HTMLElement ) {
1156
- return element . parentElement ? Array . from ( element . parentElement . children ) . indexOf ( element ) : - 1 ;
1179
+ /** Gets the index of an element among its siblings, based on their position on the page. */
1180
+ function getElementIndexByPosition ( element : HTMLElement , direction : 'top' | 'left' ) {
1181
+ if ( ! element . parentElement ) {
1182
+ return - 1 ;
1183
+ }
1184
+
1185
+ return Array . from ( element . parentElement . children )
1186
+ . sort ( ( a , b ) => a . getBoundingClientRect ( ) [ direction ] - b . getBoundingClientRect ( ) [ direction ] )
1187
+ . indexOf ( element ) ;
1157
1188
}
1158
1189
1159
1190
/**
@@ -1193,7 +1224,7 @@ function assertDownwardSorting(fixture: ComponentFixture<any>, items: Element[])
1193
1224
// Add a few pixels to the top offset so we get some overlap.
1194
1225
dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . top + 5 ) ;
1195
1226
fixture . detectChanges ( ) ;
1196
- expect ( getElementIndex ( placeholder ) ) . toBe ( i ) ;
1227
+ expect ( getElementIndexByPosition ( placeholder , 'top' ) ) . toBe ( i ) ;
1197
1228
}
1198
1229
1199
1230
dispatchMouseEvent ( document , 'mouseup' ) ;
@@ -1222,7 +1253,7 @@ function assertUpwardSorting(fixture: ComponentFixture<any>, items: Element[]) {
1222
1253
// Remove a few pixels from the bottom offset so we get some overlap.
1223
1254
dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . bottom - 5 ) ;
1224
1255
fixture . detectChanges ( ) ;
1225
- expect ( getElementIndex ( placeholder ) ) . toBe ( Math . min ( i + 1 , items . length - 1 ) ) ;
1256
+ expect ( getElementIndexByPosition ( placeholder , 'top' ) ) . toBe ( i ) ;
1226
1257
}
1227
1258
1228
1259
dispatchMouseEvent ( document , 'mouseup' ) ;
0 commit comments