react-draggable
react-draggable copied to clipboard
Is there any way to handle drag direction?
I need a way to handle if drag is going up or down, left of right? Anyone had experience with it?
If you take a look at the API
type DraggableEventHandler = (e: Event, data: DraggableData) => void | false;
type DraggableData = {
node: HTMLElement,
// lastX + deltaX === x
x: number, y: number,
deltaX: number, deltaY: number,
lastX: number, lastY: number
};
you'll probably can get the direction by computing Math.sign(deltaX) or Math.sign(deltaY)