Skip to content

Commit b677189

Browse files
authored
Merge pull request #6263 from IgniteUI/SKrastev/fix-6180-8.2.x
fix(dragDrop): Fix drag directive not positioning/transitioning ghost correctly when the page is scrolled.
2 parents 04e5229 + 03ccaae commit b677189

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,11 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
547547
}
548548

549549
protected get baseLeft(): number {
550-
return this.element.nativeElement.getBoundingClientRect().left - this.getWindowScrollLeft();
550+
return this.element.nativeElement.getBoundingClientRect().left;
551551
}
552552

553553
protected get baseTop(): number {
554-
return this.element.nativeElement.getBoundingClientRect().top - this.getWindowScrollTop();
554+
return this.element.nativeElement.getBoundingClientRect().top;
555555
}
556556

557557
protected get baseOriginLeft(): number {
@@ -744,8 +744,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
744744
if (this.ghost && this.ghostElement) {
745745
const offsetHostX = this.ghostHost ? this.ghostHostOffsetLeft(this.ghostHost) : 0;
746746
const offsetHostY = this.ghostHost ? this.ghostHostOffsetTop(this.ghostHost) : 0;
747-
this.ghostLeft = newLocation.pageX - offsetHostX;
748-
this.ghostTop = newLocation.pageY - offsetHostY;
747+
this.ghostLeft = newLocation.pageX - offsetHostX + this.getWindowScrollLeft();
748+
this.ghostTop = newLocation.pageY - offsetHostY + this.getWindowScrollTop();
749749
} else if (!this.ghost) {
750750
const deltaX = newLocation.pageX - this.pageX;
751751
const deltaY = newLocation.pageY - this.pageY;
@@ -820,16 +820,18 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
820820
if (!!startLocation && this.ghost && !this.ghostElement) {
821821
this._startX = startLocation.pageX;
822822
this._startY = startLocation.pageY;
823+
this._ghostStartX = this._startX;
824+
this._ghostStartY = this._startY;
823825
} else if (!!startLocation && (!this.ghost || this.ghostElement)) {
824826
this.setLocation(startLocation);
825827
} else if (this.ghost && !this.ghostElement) {
826828
this._startX = this.baseLeft;
827829
this._startY = this.baseTop;
830+
this._ghostStartX = this._startX + this.getWindowScrollLeft();
831+
this._ghostStartY = this._startY + this.getWindowScrollTop();
828832
}
829833

830834
if (this.ghost && !this.ghostElement) {
831-
this._ghostStartX = this._startX;
832-
this._ghostStartY = this._startY;
833835
this.createGhost(this._startX, this._startY);
834836
}
835837

@@ -889,8 +891,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
889891
this._startY = event.touches[0].pageY;
890892
}
891893

892-
this._defaultOffsetX = this.baseLeft + this.getWindowScrollLeft() - this._startX;
893-
this._defaultOffsetY = this.baseTop + this.getWindowScrollTop() - this._startY;
894+
this._defaultOffsetX = this.baseLeft - this._startX + this.getWindowScrollLeft();
895+
this._defaultOffsetY = this.baseTop - this._startY + this.getWindowScrollTop();
894896
this._ghostStartX = this._startX + this.ghostOffsetX;
895897
this._ghostStartY = this._startY + this.ghostOffsetY;
896898
this._lastX = this._startX;
@@ -1298,8 +1300,8 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {
12981300
}
12991301

13001302
if (this.ghost && this.ghostElement) {
1301-
this._ghostStartX = this.baseLeft;
1302-
this._ghostStartY = this.baseTop;
1303+
this._ghostStartX = this.baseLeft + this.getWindowScrollLeft();
1304+
this._ghostStartY = this.baseTop + this.getWindowScrollTop();
13031305

13041306
const ghostDestroyArgs: IDragGhostBaseEventArgs = {
13051307
owner: this,

0 commit comments

Comments
 (0)