metal / metal.js

Build UI components in a solid, flexible way
http://metaljs.com
Other
229 stars 59 forks source link

dom.contains method does not support SVG elements in IE11 #404

Open jaredgorski opened 5 years ago

jaredgorski commented 5 years ago

dom.contains: https://github.com/metal/metal.js/blob/master/packages/metal-dom/src/domNamed.js#L211-L225

We are experiencing an error in IE11 when dom.contains is called in metal-dom in events.js, because we are trying to handle events on an SVG element. We are experiencing this error:

screen shot 2019-01-18 at 12 11 22 pm

When hovering over the ? icon, IE DevTools yields this error:

SCRIPT438: Object doesn't support property or method 'contains'
File: common.js, Line 1, Column 998455

It turns out that IE has limited support of HTML DOM node methods (like Node.contains), as in, it doesn't support searching for an SVG element inside a DOM node. Our use case happens to be causing this function to search inside an SVG element for a path element, which works in Chrome and FF but is invalid in IE11.

@eduardolundgren made a good point about this. According to him, Metal used to have a dom.contains method that used compareDocumentPosition() to compare the position binaries in the DOM tree to see if an element is a descendent of another. A solution like this may bring back full support for contains in IE11. The solution might be identical to this one: https://github.com/google/closure-library/blob/e656c0807353188f42b67722d56724a5afc13228/closure/goog/dom/dom.js#L1519-L1542

@jbalsas