I am doing Drag and Drop may be in a bit different manner. But see here, I actually used below code on DragMove event handler, to handle scroll while dragging an item.
const viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
const scrollTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
const scrollLimit = document.body.scrollHeight - viewPortHeight;
// See if we need to scroll while dragging
if (scrollLimit >= 0) {
const scrollSpeed = 20;
const scrollSensitivity = 50;
if (((event.pageY - scrollTop) <= scrollSensitivity)) {
window.scrollTo(0, (scrollTop - scrollSpeed));
} else if (((viewPortHeight + scrollTop - event.pageY) <= scrollSensitivity) && (scrollTop <= scrollLimit)) {
// mobile browsers sometimes report scrollTop as 0, this hack gets the accurate value
if (scrollTop === 0) { window.scrollTo(0, 1); }
window.scrollTo(0, (scrollTop + scrollSpeed));
}
}
I am not sure, whether the above code is suitable or not but Here is a full React example, may help for you..
https://devtrigger.com/drag-and-drop-elements-with-auto-scroll/