Prevent exception when drag event target not under svg #384
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🐛 Bug Fix
In order to have a continuous dragging even if my mouse gets out of the
<svg>
element, I attachdragMove
anddragEnd
to thewindow
object in my code.However, these events are no longer guaranteed to have a
target
under a<svg>
, provoking an exception in@vx/event
:This exception is fixed by the changes of this PR.
🏠 Internal
outermostSVGElement
fromlocalPoint
: a function that retrieves the englobing SVG element of a node.localPoint
uses it on theevent.target
if nonode
was passed, but we may want to use another element as thenode
and use the same function to retrieve the outermost SVG element.For example, the next commit uses it in
Drag
to always use the outermost SVG element from theg
instead of the one from the event, because that event could have a target outside the SVG tree.