scala-js/scala-js-dom

querySelectorAll should return Elements

theqp opened this issue · 5 comments

theqp commented
  1. It's inconsistent with querySelector which returns Element
  2. It's inconsistent with the MDN Web Docs

A non-live NodeList containing one Element object for each element that matches at least one of the specified selectors or an empty NodeList in case of no matches.

raquo commented

querySelectorAll returns a NodeList of Element-s:

def querySelectorAll(selectors: String): NodeList = js.native

This matches what the MDN page that you quoted says that the JavaScript method returns.

I'm not sure what you mean by "inconsistent with querySelector", but scala-js-dom doesn't have a choice here. This interface follows the design of the underlying Javascript methods. Javascript querySelectorAll method returns a NodeList, and that's what scala-js-dom has to return as well for that method definition.

theqp commented

@raquo The definition of NodeList is:
class NodeList extends DOMList[Node]
The MDN documentations states querySelector returns Elements, not Nodes thus I think it should return DOMList[Element]

raquo commented

Ah, I see what you mean now.

I guess one way to encode it would be class NodeList[N <: Node] extends DOMList[N].

theqp commented

@raquo
We already have an equivalent

trait NodeListOf[TNode <: Node] extends DOMList[TNode]

@theqp or @raquo would you mind making a PR for this? Would be much appreciated! :)