Skip to content

Commit 31b50bc

Browse files
authored
fix(igxDrag): Restore ghost template when moving drag elements around. (#13807)
1 parent 8675f16 commit 31b50bc

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
@@ -16,7 +16,8 @@ import {
1616
TemplateRef,
1717
ContentChildren,
1818
QueryList,
19-
RendererStyleFlags2
19+
RendererStyleFlags2,
20+
EmbeddedViewRef
2021
} from '@angular/core';
2122
import { animationFrameScheduler, fromEvent, interval, Subject } from 'rxjs';
2223
import { takeUntil, throttle } from 'rxjs/operators';
@@ -623,7 +624,7 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
623624
protected _ghostStartY;
624625
protected _ghostHostX = 0;
625626
protected _ghostHostY = 0;
626-
protected _dynamicGhostRef;
627+
protected _dynamicGhostRef: EmbeddedViewRef<any>;
627628

628629
protected _pointerDownId = null;
629630
protected _clicked = false;
@@ -1131,6 +1132,25 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
11311132
return;
11321133
}
11331134

1135+
// When the base element is moved to previous index, angular reattaches the ghost template as a sibling by default.
1136+
// This is the defaut place for the EmbededViewRef when recreated.
1137+
// That's why we need to move it to the proper place and set pointer capture again.
1138+
if (this._pointerDownId && this.ghostElement && this._dynamicGhostRef && !this._dynamicGhostRef.destroyed) {
1139+
let ghostReattached = false;
1140+
if (this.ghostHost && !Array.from(this.ghostHost.children).includes(this.ghostElement)) {
1141+
ghostReattached = true;
1142+
this.ghostHost.appendChild(this.ghostElement);
1143+
} else if (!this.ghostHost && !Array.from(document.body.children).includes(this.ghostElement)) {
1144+
ghostReattached = true;
1145+
document.body.appendChild(this.ghostElement);
1146+
}
1147+
1148+
if (ghostReattached) {
1149+
this.ghostElement.setPointerCapture(this._pointerDownId);
1150+
return;
1151+
}
1152+
}
1153+
11341154
const eventArgs = {
11351155
originalEvent: event,
11361156
owner: this,

0 commit comments

Comments
 (0)