-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
Event handling to use target instead currentTarget #5575
Conversation
If you attach event handlers to a container rather than directly to the canvas then the currentTarget is the container, event.target is the canvas that triggers the event. It's useful to do this if you have many charts or are creating them dynamically.
In the case of the event handler attached to the canvas, |
Hi, sorry about the delay. Here is a fiddle, https://jsfiddle.net/e8n4xd4z/11575/ The handler attached to the chart finds an element when it is clicked, the handler attached to the body does not. |
@teroman what do you think about being able to add a unit test? |
Hi, I'm not sure how to write a test for an interactive event like this. I can't see any existing tests that call getElementAtEvent or getRelativePosition. If you could point me to any existing test for those I will try to adapt them to test this change. |
I think all unit tests in interaction.test.js already check if these methods work correctly. Maybe that's enough. I don't know this section of the code well enough to understand the difference between |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, let's merge this change.
If you attach event handlers to a container rather than directly to the canvas then the currentTarget is the container, event.target is the canvas that triggers the event. It's useful to do this if you have many charts or are creating them dynamically.
If you attach event handlers to a container rather than directly to the canvas then the currentTarget is the container, event.target is the canvas that triggers the event.
It's useful to do this if you have many charts or are creating them dynamically.