Skip to content

Commit 80dbacf

Browse files
committed
fix(scrollpoint): calculate scroll on dragenter
1 parent 507e1ca commit 80dbacf

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

projects/ng-sortgrid/src/lib/ngsg-item.directive.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,18 @@ describe('NgsgItemDirective', () => {
221221
sut.drop();
222222
expect(consoleWarnSpy).toHaveBeenCalledWith(expectedWarniningMessage);
223223
});
224+
225+
it('should call the scrollHelper once we drag', () => {
226+
const event = {
227+
target: 'Some target'
228+
};
229+
const scrollPointTop = 20;
230+
const scrollSpeed = 50;
231+
sut.scrollPointTop = scrollPointTop;
232+
sut.scrollSpeed = scrollSpeed;
233+
spyOn(scrollHelperService, 'scrollIfNecessary');
234+
235+
sut.drag(event);
236+
expect(scrollHelperService.scrollIfNecessary).toHaveBeenCalledWith(event.target, {top: scrollPointTop}, scrollSpeed);
237+
});
224238
});

projects/ng-sortgrid/src/lib/ngsg-item.directive.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,13 @@ export class NgsgItemDirective implements OnInit, OnChanges, AfterViewInit, OnDe
8888
this.sortService.sort(this.el.nativeElement);
8989
}
9090

91+
@HostListener('drag', ['$event'])
92+
drag(event): void {
93+
this.scrollHelperService.scrollIfNecessary(event.target, {top: this.scrollPointTop}, this.scrollSpeed);
94+
}
95+
9196
@HostListener('dragover', ['$event'])
9297
dragOver(event): boolean {
93-
94-
if (this.viewPortService.isOutOfViewport(event.target).top) {
95-
window.scrollBy({top: -this.SCROLLSPEED, behavior: 'smooth'});
96-
}
97-
98-
if (this.viewPortService.isOutOfViewport(event.target).bottom) {
99-
window.scrollBy({top: this.SCROLLSPEED, behavior: 'smooth'});
100-
}
101-
10298
if (event.preventDefault) {
10399
// Necessary. Allows us to drop.
104100
event.preventDefault();

0 commit comments

Comments
 (0)