Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,9 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {

protected get ghostLeft() {
if (this.ghostElement) {
return parseInt(this.ghostElement.style.left, 10) + this._ghostHostX;
// Includes the margin, like the pageX the setter takes.
const ghostMarginLeft = parseInt((this.document.defaultView!.getComputedStyle(this.ghostElement) as any)['margin-left'], 10);
return parseInt(this.ghostElement.style.left, 10) + ghostMarginLeft + this._ghostHostX;
}
return undefined!;
}
Expand All @@ -605,7 +607,9 @@ export class IgxDragDirective implements AfterContentInit, OnDestroy {

protected get ghostTop() {
if (this.ghostElement) {
return parseInt(this.ghostElement.style.top, 10) + this._ghostHostY;
// Includes the margin, like the pageY the setter takes.
const ghostMarginTop = parseInt((this.document.defaultView!.getComputedStyle(this.ghostElement) as any)['margin-top'], 10);
return parseInt(this.ghostElement.style.top, 10) + ghostMarginTop + this._ghostHostY;
}
return undefined!;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,32 @@ describe('igxDrag window auto-scroll', () => {
expect(drag.ghostElement).toBeTruthy();
};

it('should scroll the window and move the ghost with it while dragging near the bottom of the viewport', async () => {
const firstDrag = fix.componentInstance.dragElems.first;
const maxScrollY = document.documentElement.scrollHeight - document.documentElement.clientHeight;
expect(maxScrollY).toBeGreaterThan(0);

await dragToViewportBottom(firstDrag);
const ghostRect = firstDrag.ghostElement.getBoundingClientRect();

await vi.waitFor(() => expect(window.scrollY).toBeGreaterThan(0));
expect(firstDrag.ghostElement.getBoundingClientRect().top).toBe(ghostRect.top);
expect(firstDrag.ghostElement.getBoundingClientRect().left).toBe(ghostRect.left);

// The ghost extends the document while it moves down, but scrolling stops (within one 5px step)
// at the size the document had when scrolling started.
await vi.waitFor(() => expect(window.scrollY).toBeGreaterThanOrEqual(maxScrollY));
const finalScrollY = window.scrollY;
await wait(100);
expect(window.scrollY).toBe(finalScrollY);
expect(finalScrollY).toBeLessThan(maxScrollY + 5);
expect(firstDrag.ghostElement.getBoundingClientRect().top).toBe(ghostRect.top);
expect(firstDrag.ghostElement.getBoundingClientRect().left).toBe(ghostRect.left);

UIInteractions.simulatePointerEvent('pointerup', firstDrag.ghostElement, ghostRect.left, ghostRect.top + finalScrollY);
expect(firstDrag.ghostElement).toBeNull();
});

it('should stop scrolling the window when destroyed while auto-scrolling', async () => {
const firstDrag = fix.componentInstance.dragElems.first;
await dragToViewportBottom(firstDrag);
Expand Down