I have tried some ways to implement this, hope they are helpful:
- react-dnd-scrollzone.
This package can make a container scrolling when you drag the draggable component to the edge of the container. However, it has to be applied to a warpped container, which is not the purpose of my object, so I get rid of it.
- Implementing the scroll behavior in the
rowSource
const rowSource = {
isDragging(props, monitor) {
// determine mouse position
const clientOffset = monitor.getClientOffset();
if (clientOffset) {
// you can implement your own scroll behavior here
// scroll up if dragging to an upper area
const moveThreshold = Math.max(120, window.innerHeight / 4);
if (clientOffset.y < moveThreshold && !window.isScrolling) {
// scroll up
window.isScrolling = true;
$("html, body").animate(
{
scrollTop: window.pageYOffset - moveThreshold,
},
{
duration: 300,
complete: () => {
window.isScrolling = false;
},
}
);
}
}
},
};
@DragSource("YOUR_DRAG_TYPE", rowSource, (connect, monitor) => ({
connectDragSource: connect.dragSource(),
}))
class DraggableItem extends Component {
// your component
}