-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mouseEvent doesn't have offsetX/offsetY #4431
Comments
Oh, well, I see. |
This shows all available values: onClick(event) {
event.persist();
console.log(event);
} Using the |
@cody thanks! |
👍 Please close if you're happy with the answer and there is no found bug(s). |
You probably want pageX or clientX and if you want it relative to another element you can use getBoundingClientRect on that element – if you do that it should work well across browsers. |
Any chance of adding them into React - perhaps with a https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX |
That seems reasonable enough if we can do it with no performance compromise so I'll reopen this, but it won't be a high priority for us. |
I did some work on this and it would require a polyfill. As a property in SyntheticMouseEvent it would execute for every mouse event, which would have a performance impact. It could be added as a method that executed on-demand but then it wouldn't match the native MouseEvent interface. |
I’ll close since we decided to not merge #7011. |
As of 2020, this doesn't seem to need a polyfill. But I can submit a PR if you want |
@gaearon, Why ReactJs mouseEvent doesn't have Why the Facebook developers add them into |
@amerllica |
Can we reopen this? offsetX would make it a lot easier to implemenet encapsulated event handlers. |
Is there any solution offer by react , other then the getBoundingClientRect and e.nativeEvent for handling the mouse event ?? |
This was closed in 2016. It's 2024 and
@sebmarkbage you're the most active maintainer during the past month: https://github.com/facebook/react/graphs/contributors. @gaearon, who initially engaged in this thread and ultimately closed in the issue in 2016 is no longer working on React presumably since he moved to Bluesky. Can this be re-opened? |
I try get position of click relative to element, but event doesn't have offsetX.
How I can get position of click in element?
The text was updated successfully, but these errors were encountered: