question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Click events are swallowed by SVG <use> elements in IE

See original GitHub issue

We’ve only managed to replicate this in Edge and <=IE11, not Chrome or Firefox. We’ve created a demo of the issue with this jsbin.

We’re using a common SVG element and linking to it with xlink:href as is common with SVG icons. When linking to the icons with a <use> tag inside an anchor, all click events on the icon will not bubble to onClick handlers on the anchor.

An example: I have a common SVG element with an icon <svg><rect id="my-icon" width="100" height="100"></rect></svg>. I then make a link containing my icon <a href="https://github.com"><svg dangerouslySetInnerHTML={{__html: '<use xlink:href="#my-icon"></use>'}}></svg></a>. As xlink:href isn’t supported by react yet, we have to use dangerouslySetInnerHTML. If we now click the SVG any onClick handlers on the anchor will not run.

A temporary workaround is setting pointer-events: none on the SVG element inside the anchor.

This might be a dupe of #1509

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

18reactions
matthew-deancommented, Apr 26, 2018

Per the Stack Overflow comments, what worked for us was just to add pointer-events: none to <svg> and <use> elements.

6reactions
Shepardcommented, Mar 15, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

Click events are swallowed by SVG <use> elements in IE/Edge
We're using a common SVG element and linking to it with xlink:href as is common with SVG icons. When linking to the icons...
Read more >
Mouse pointer hover/jquery click event on SVG embedded in ...
In my experience, SVG embedded as <object> elements tend to swallow pointer events (because the browser creates a new document inside the ...
Read more >
<svg> elements respond to mouse events when they should not
In Safari, SVG elements don't consume mouse events by default, and the behavior can be controlled with the pointer-events setting, which is very...
Read more >
Working around SVG Swallowing Click Events - Toggen
To work around this using styled JSX requires the use of a :global statement to make the required pointer-events: none apply to the...
Read more >
UI Events - W3C
Both HTML and SVG have an <a> element which indicates a link. Relevant activation triggers for an <a> element are a click event...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found