@@ -17,7 +17,8 @@ import {
1717 ContentChildren ,
1818 QueryList ,
1919 RendererStyleFlags2 ,
20- booleanAttribute
20+ booleanAttribute ,
21+ EmbeddedViewRef
2122} from '@angular/core' ;
2223import { animationFrameScheduler , fromEvent , interval , Subject } from 'rxjs' ;
2324import { takeUntil , throttle } from 'rxjs/operators' ;
@@ -624,7 +625,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
624625 protected _ghostStartY ;
625626 protected _ghostHostX = 0 ;
626627 protected _ghostHostY = 0 ;
627- protected _dynamicGhostRef ;
628+ protected _dynamicGhostRef : EmbeddedViewRef < any > ;
628629
629630 protected _pointerDownId = null ;
630631 protected _clicked = false ;
@@ -1132,6 +1133,25 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
11321133 return ;
11331134 }
11341135
1136+ // When the base element is moved to previous index, angular reattaches the ghost template as a sibling by default.
1137+ // This is the defaut place for the EmbededViewRef when recreated.
1138+ // That's why we need to move it to the proper place and set pointer capture again.
1139+ if ( this . _pointerDownId && this . ghostElement && this . _dynamicGhostRef && ! this . _dynamicGhostRef . destroyed ) {
1140+ let ghostReattached = false ;
1141+ if ( this . ghostHost && ! Array . from ( this . ghostHost . children ) . includes ( this . ghostElement ) ) {
1142+ ghostReattached = true ;
1143+ this . ghostHost . appendChild ( this . ghostElement ) ;
1144+ } else if ( ! this . ghostHost && ! Array . from ( document . body . children ) . includes ( this . ghostElement ) ) {
1145+ ghostReattached = true ;
1146+ document . body . appendChild ( this . ghostElement ) ;
1147+ }
1148+
1149+ if ( ghostReattached ) {
1150+ this . ghostElement . setPointerCapture ( this . _pointerDownId ) ;
1151+ return ;
1152+ }
1153+ }
1154+
11351155 const eventArgs = {
11361156 originalEvent : event ,
11371157 owner : this ,
0 commit comments