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

onclick={{action 'myAction'}} doesn't work on svg elements #13420

Closed
andressrg opened this issue Apr 27, 2016 · 14 comments
Closed

onclick={{action 'myAction'}} doesn't work on svg elements #13420

andressrg opened this issue Apr 27, 2016 · 14 comments

Comments

@andressrg
Copy link

Adding onclick={{action 'myAction'}} to an svg element does not work as expected and throws an error.

The action function seems to be inlined on the element. But still throws an error.
screenshot 2016-04-26 19 04 50

Reproduction twiddle: https://ember-twiddle.com/ab12e8e67d1fb5ae7783aa2703a13043?openFiles=templates.components.my-svg.hbs%2Ctemplates.components.my-svg.hbs

  • Open the console
  • Click on Here it works -> console prints Clicked!
  • Click on The black SVG triangle -> console prints Uncaught SyntaxError: Unexpected token (
@andressrg andressrg changed the title onclick={{action 'myAction'}} doesn't work on svg elements onclick={{action 'myAction'}} doesn't work on svg elements Apr 27, 2016
@rwjblue
Copy link
Member

rwjblue commented Apr 27, 2016

When in the svg namespace we always set attribute (not properties). When you set an attribute to a function, it will set the attribute to the string value of the function instead.

@pixelhandler
Copy link
Contributor

@andressrg It sounds like we need more documentation on SVG use in component, especially regarding actions. I didn't know that when using SVG the attribute will become the string value. So It sounds like you may need a workaround. How about using browser events instread?

See https://ember-twiddle.com/397a27e5a050c5caf35bd4f2a8b37af1?openFiles=components.my-svg.js%2Ctemplates.components.my-svg.hbs

@locks is there documenation available or in the works regarding using SVG elements in Ember components?

@krisselden
Copy link
Contributor

@rwjblue I think if onclick={{action 'my-action'}} works on any element it should work on all elements that support onclick no? I'm going to label this as a bug.

@krisselden krisselden added the Bug label May 19, 2016
@rwjblue
Copy link
Member

rwjblue commented May 19, 2016

@krisselden - I was not justifying that the current behavior was correct, I was explaining what is happening.

@mixonic
Copy link
Sponsor Member

mixonic commented Jun 26, 2016

This would also be addressed by attr-first-but-special-behavior-when-type-of-function in Glimmer

@tonyhschu
Copy link

Any word on what the fix might be?

@lifeart
Copy link
Contributor

lifeart commented Apr 12, 2017

UP, same error with Glimmerjs

@lllama
Copy link

lllama commented May 8, 2017

Just seen this in Glimmer as well - if anyone has a work around then that would be great.

@lifeart
Copy link
Contributor

lifeart commented Aug 26, 2017

@lllama, @tonyhschu this works for me:

<polygon points="300,1007.5 300,1550 0,775 300,0 300,542.5 2050,542.5 2050,1007.5"
    {{action "someAction"}}> </polygon>

@fyzwjd
Copy link

fyzwjd commented Sep 27, 2017

When I use onmouseover={{action "someAction"}} - it has similar problem

@MrChriZ
Copy link

MrChriZ commented May 10, 2018

I ran into this with FontAwesome 5. I didn't even get any console error messages.
Lifearts fix worked for me however.

@pixelhandler
Copy link
Contributor

@MrChriZ @andressrg @fredguth @fyzwjd @krisselden @lifeart @lllama @mixonic @rwjblue @tonyhschu is this still an issue, perhaps we should close or create a new reproduction of this, what do you think?

@pixelhandler
Copy link
Contributor

Closing for now, feel free to re-open if you can reproduce in the current release of Ember.

@shanekoss
Copy link

This works great in Chrome, but without onclick, you can't get an event to make this work in Firefox. Any other workarounds?

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