Skip to content

Commit 236c5a4

Browse files
authored
Merge branch '17.0.x' into mkirova/fix-13798-17.0.x
2 parents f8c8c7f + 5c4b8e2 commit 236c5a4

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

projects/igniteui-angular/src/lib/directives/drag-drop/drag-drop.directive.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
ContentChildren,
1818
QueryList,
1919
RendererStyleFlags2,
20-
booleanAttribute
20+
booleanAttribute,
21+
EmbeddedViewRef
2122
} from '@angular/core';
2223
import { animationFrameScheduler, fromEvent, interval, Subject } from 'rxjs';
2324
import { 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

Comments
 (0)