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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events are not properly bound to SVG elements #17221

Closed
ondrejsevcik opened this issue Nov 22, 2018 · 2 comments
Closed

Events are not properly bound to SVG elements #17221

ondrejsevcik opened this issue Nov 22, 2018 · 2 comments

Comments

@ondrejsevcik
Copy link

ondrejsevcik commented Nov 22, 2018

Hi, I've found a small inconsistency when working with SVG and actions in Ember.

I've tried to bind action on mouseEnter on rect element but it doesn't work with ember action.

<rect onMouseEnter={{action "log"}}></rect>

With div, this works without any problem.

I’ve also tried to handle it with native javascript and that works.

<rect onmouseenter="javascript:alert('native works')"></rect>

Here's the twiddle with reproduction
https://ember-twiddle.com/d9db8b82d40cbc4fcfb4c33cff34ab4e?openFiles=templates.application.hbs%2C

@ondrejsevcik ondrejsevcik changed the title Events are not properly bind to SVG elements Events are not properly bound to SVG elements Dec 3, 2018
@rwjblue
Copy link
Member

rwjblue commented Dec 7, 2018

I don't believe this is a bug per-se, using the element modifier version of {{action}} works properly:

https://ember-twiddle.com/eef22b20be320ac16259b5ce0b4f0b17?openFiles=templates.application.hbs%2C

The way Ember assigns things to an element depends on what type of Element it is. Specifically, if the element has a property for the thing being assigned (onmouseenter) we set it as a property (el.onmouseenter = value), if it does not find that particular property in the element we set an attribute (el.setAttribute('onmouseenter', value)). Unlike "normal" HTML elements, SVG elements often do not have properties on their prototype chain for events, therefore assigning a function to rectElement.onmouseenter has no effect.

Using the element modifier version of {{action}} is the right way to handle eventing when dealing with SVG elements, though a future RFC (e.g. emberjs/rfcs#314) may change that.

@rwjblue rwjblue removed the Bug label Dec 7, 2018
@rwjblue rwjblue closed this as completed Dec 7, 2018
@ondrejsevcik
Copy link
Author

ondrejsevcik commented Dec 10, 2018

Using element modifier version of action helper doesn't help in my case as I need to get mouse coordinates from mouse event object. But this event object is not passed in when using modifier version.

As a workaround I've created a component with a tagName: 'rect' and attach required mouse events on it. That works, but it still feels like a workaround, especially when assigning action to property on any other HTML element works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants