Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent exception when drag event target not under svg #384

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

madprog
Copy link

@madprog madprog commented Nov 23, 2018

馃悰 Bug Fix

  • In order to have a continuous dragging even if my mouse gets out of the <svg> element, I attach dragMove and dragEnd to the window object in my code.
    However, these events are no longer guaranteed to have a target under a <svg>, provoking an exception in @vx/event:

    vx-event.es.js:15 Uncaught TypeError: Cannot read property 'ownerSVGElement' of undefined
        at localPoint (vx-event.es.js:15)
        at Drag.dragMove (vx-drag.es.js:121)
        at DragViewBase._this.handleMouseMove (DraggableSvg.tsx:75)
    

    This exception is fixed by the changes of this PR.

馃彔 Internal

  • Extracted outermostSVGElement from localPoint: a function that retrieves the englobing SVG element of a node. localPoint uses it on the event.target if no node was passed, but we may want to use another element as the node 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 the g instead of the one from the event, because that event could have a target outside the SVG tree.

In the case where the event handlers are bound to window, they may
receive events from nodes outside of the SVG node, so Drag needs to
retrieve them in another way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants