react-draggable
react-draggable copied to clipboard
[Feature Request]Custom snap callback
I want to implement a custom snapping to certain element borders so that I can align elements at the top/left/bottom/right.
I've tried many approaches but couldn't find a way to overwrite the current position in onDrag.
Now I found a way that works great so far, but it's a nasty hack: I injected this code in the onDrag method in the Draggable component:
if (this.snapX) {
newState.x = this.snapX(newState.x);
}
Now I can go to my componentDidMount method and write this:
this.draggable.snapX = this.snapX;
Thereby I can now write a custom snap calculation function that allows setting the position while dragging.
Of course I would prefer a clean solution. Maybe it would be possible to add one more prop "customSnap" for a custom callback that can modify the drag position while dragging?
Has this been assigned any priority? Is PR accepted for this?
I'm also interested in adding this in a PR.
Yea, i'd like to be able to snap it on certain corners (or all) of the document. Is this achievable nowadays?