react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

[Feature Request]Custom snap callback

Open mididev opened this issue 8 years ago • 3 comments
trafficstars

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?

mididev avatar Aug 23 '17 10:08 mididev

Has this been assigned any priority? Is PR accepted for this?

gajus avatar Oct 30 '17 09:10 gajus

I'm also interested in adding this in a PR.

pahen avatar Sep 28 '18 07:09 pahen

Yea, i'd like to be able to snap it on certain corners (or all) of the document. Is this achievable nowadays?

mmarzullotv avatar Mar 16 '23 19:03 mmarzullotv