You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I'm making a simple SVG game. I want to make custom elements with shadow roots that consist of SVG primitives (<rect>, <circle>, etc). The result would be like this:
where each one of those elements could be defined as
customElements.define('player-tank',classextendsSVGRectElement{constructor(){this.root=this.attachShadow({mode:'closed'})this.root.innerHTML=`<rect width="10" height="10"></rect>`// ... some more code to map `position` attribute to `x/y` attributes ...}})
Demo (nothing happens): https://jsfiddle.net/pem90k9a (but if you try to place the player-tank element outside of an SVG tree, then it will say Uncaught TypeError: Illegal constructor anyways since we've extended SVGRectElement.
Why is SVG not component-friendly?
The text was updated successfully, but these errors were encountered:
A solution is to use <div>s, and each item (player-tank, enemy-tank, etc) can be a separate <svg> tree, but anyways it would still be intuitive for it to just work (rather than resulting in nothing).
trusktr
changed the title
[bug] Unable to build web components for use in an SVG context
[question] Why are we unable to build web components from SVG elements?
Jul 22, 2017
It just needs to look at the composed tree. The rendering should be decoupled from parsing, it would be proper. Idk how complex that is, but it seems worthwhile.
Suppose I'm making a simple SVG game. I want to make custom elements with shadow roots that consist of SVG primitives (
<rect>
,<circle>
, etc). The result would be like this:where each one of those elements could be defined as
Demo (nothing happens): https://jsfiddle.net/pem90k9a (but if you try to place the
player-tank
element outside of an SVG tree, then it will sayUncaught TypeError: Illegal constructor
anyways since we've extendedSVGRectElement
.Why is SVG not component-friendly?
The text was updated successfully, but these errors were encountered: