open-amdocs / webrix

Powerful building blocks for React-based web applications
https://webrix.amdocs.com
Apache License 2.0
432 stars 32 forks source link

Movable - [Feature Request] - relative coordinates in `update` callback #37

Closed yairEO closed 3 years ago

yairEO commented 3 years ago

The update callback is fired with top & left coordinates which are relative to the viewport, but in some situations it is preferred to be relative to the container (set in the contain operation). I suggest telling the Movable component this, in some way. Perhaps add a 3rd parameter to the contain operation which will indicate this wish.

ykadosh commented 3 years ago

Thanks for reporting! I've also identified the need for that and started to work on a new operation called relative(ref) which will convert the coordinates to be relative to the given ref. I'm still working out the details, but it will be part of v1.3

yairEO commented 3 years ago

Found a bug related to this new change:

https://codesandbox.io/s/agitated-wind-5j6t9?file=/Example.jsx

https://user-images.githubusercontent.com/845031/118973858-d07e0300-b97a-11eb-9037-da299a5f4c28.mp4

Steps to reproduce:

When simply clicking the movable element (not dragging) - Update callback is fired with undesired left/top values.

Expected:

values should be an exact multiply of the snap setting value (which is set to in this example 50)

What is happening instead?

Need to investigate why this is happening and not simply round before sending the position values

{left: 199.9999771118164, top: 99.98579406738281}

This might seem insignificant, but is has huge impact on some use-cases