@@ -562,7 +562,7 @@ describe('CdkDrag', () => {
562562 // Add a few pixels to the left offset so we get some overlap.
563563 dispatchMouseEvent ( document , 'mousemove' , elementRect . left + 5 , elementRect . top ) ;
564564 fixture . detectChanges ( ) ;
565- expect ( getElementIndex ( placeholder ) ) . toBe ( i ) ;
565+ expect ( getElementIndexByPosition ( placeholder , 'left' ) ) . toBe ( i ) ;
566566 }
567567
568568 dispatchMouseEvent ( document , 'mouseup' ) ;
@@ -590,7 +590,7 @@ describe('CdkDrag', () => {
590590 // Remove a few pixels from the right offset so we get some overlap.
591591 dispatchMouseEvent ( document , 'mousemove' , elementRect . right - 5 , elementRect . top ) ;
592592 fixture . detectChanges ( ) ;
593- expect ( getElementIndex ( placeholder ) ) . toBe ( Math . min ( i + 1 , items . length - 1 ) ) ;
593+ expect ( getElementIndexByPosition ( placeholder , 'left' ) ) . toBe ( i ) ;
594594 }
595595
596596 dispatchMouseEvent ( document , 'mouseup' ) ;
@@ -660,6 +660,31 @@ describe('CdkDrag', () => {
660660 expect ( placeholder . textContent ! . trim ( ) ) . toContain ( 'Custom placeholder' ) ;
661661 } ) ) ;
662662
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+
663688 } ) ;
664689
665690 describe ( 'in a connected drop container' , ( ) => {
@@ -1151,9 +1176,15 @@ function dragElementViaTouch(fixture: ComponentFixture<any>,
11511176 fixture . detectChanges ( ) ;
11521177}
11531178
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 ) ;
11571188}
11581189
11591190/**
@@ -1193,7 +1224,7 @@ function assertDownwardSorting(fixture: ComponentFixture<any>, items: Element[])
11931224 // Add a few pixels to the top offset so we get some overlap.
11941225 dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . top + 5 ) ;
11951226 fixture . detectChanges ( ) ;
1196- expect ( getElementIndex ( placeholder ) ) . toBe ( i ) ;
1227+ expect ( getElementIndexByPosition ( placeholder , 'top' ) ) . toBe ( i ) ;
11971228 }
11981229
11991230 dispatchMouseEvent ( document , 'mouseup' ) ;
@@ -1222,7 +1253,7 @@ function assertUpwardSorting(fixture: ComponentFixture<any>, items: Element[]) {
12221253 // Remove a few pixels from the bottom offset so we get some overlap.
12231254 dispatchMouseEvent ( document , 'mousemove' , elementRect . left , elementRect . bottom - 5 ) ;
12241255 fixture . detectChanges ( ) ;
1225- expect ( getElementIndex ( placeholder ) ) . toBe ( Math . min ( i + 1 , items . length - 1 ) ) ;
1256+ expect ( getElementIndexByPosition ( placeholder , 'top' ) ) . toBe ( i ) ;
12261257 }
12271258
12281259 dispatchMouseEvent ( document , 'mouseup' ) ;
0 commit comments