scala-js/scala-js-dom

make SVG html element

antonkulaga opened this issue · 6 comments

I wonder why

<svg>
</svg>

does not inherit HTMLElement?

Because it isn't one

screenshot 2015-10-12 11 48 21

As to "why", that's beyond my pay grade =P

sjrd commented

Exactly what I was going to say. Also documented here: https://developer.mozilla.org/en-US/docs/Web/API/SVGSVGElement

We have SVGElement, which extends Element. Techically I also think that HTMLDocument and SVGDocument's createElement should return the more specific type (HTMLElement/SVGElement), but currently they do not (they punt and return Element iirc).

Is there any reason we shouldn't do some path dependent magic here?

sjrd commented

@mseddon I agree we should improve the result type of createElement and, if possible, other such methods, but that is another issue.

SVGElement has a bunch of fields that are the same as HTMLElement, in particular

  var onmousemove: js.Function1[MouseEvent, _] = js.native
  var onmouseout: js.Function1[MouseEvent, _] = js.native
  var ondblclick: js.Function1[MouseEvent, _] = js.native
  var onfocusout: js.Function1[FocusEvent, _] = js.native
  var onfocusin: js.Function1[FocusEvent, _] = js.native

maybe we can hve a trait with them from which both HTMLElement and SVGElement will extend? In such case I will be able to operate with HTMLElements and SVGElements in a same manner when I only care about event subscriptions

I can see this already addressed in the codebase.