Secretmapper / react-image-annotation

An infinitely customizable image annotation library built on React
https://secretmapper.github.io/react-image-annotation/
MIT License
329 stars 135 forks source link

Fix for inconsistent values from nativeEvent.offsetX and Y #19

Closed stevehawley closed 5 years ago

stevehawley commented 5 years ago

I was exploring a change to address issue #14 and ran into an issue with the selector that was caused by the use of offsetX and offsetY in getCoordPercentage.

MouseEvent offsets give inconsistent results when dragging up and to the left rather than the more natural down and to the right. The reason could be browser implementation (it is still experimental) or it could be that nativeEvent offsets are based on target rather than currentTarget, I don't know.

To keep consistent behavior with the selector use the bounding client rect to calculate offset values for the current element.

Secretmapper commented 5 years ago

Thanks for the PR!