Event handling to use target instead currentTarget#5575
Event handling to use target instead currentTarget#5575simonbrunel merged 1 commit intochartjs:masterfrom
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 |
simonbrunel
left a comment
There was a problem hiding this comment.
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.