Skip to content

Improve HTMLCollection, add HTMLOptionsCollection and HTMLFormControlsCollection #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 17, 2021
1,008 changes: 506 additions & 502 deletions api-reports/2_12.txt

Large diffs are not rendered by default.

1,008 changes: 506 additions & 502 deletions api-reports/2_13.txt

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/main/scala/org/scalajs/dom/Document.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ abstract class Document extends Node with NodeSelector with DocumentEvent with P
* root node. The returned HTMLCollection is live, meaning that it updates itself automatically to stay in sync with
* the DOM tree without having to call document.getElementsByTagName again.
*/
def getElementsByTagName(name: String): HTMLCollection = js.native
def getElementsByTagName(name: String): HTMLCollection[Element] = js.native

/** Returns a list of elements with the given tag name belonging to the given namespace. The complete document is
* searched, including the root node.
*/
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection = js.native
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection[Element] = js.native

/** Returns a set of elements which have all the given class names. When called on the document object, the complete
* document is searched, including the root node. You may also call getElementsByClassName on any element; it will
* return only elements which are descendants of the specified root element with the given class names.
*/
def getElementsByClassName(classNames: String): HTMLCollection = js.native
def getElementsByClassName(classNames: String): HTMLCollection[Element] = js.native

/** Returns the element from the document whose elementFromPoint method is being called which is the topmost element
* which lies under the given point.  To get an element, specify the point via coordinates, in CSS pixels, relative
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/scalajs/dom/Element.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,17 +167,17 @@ abstract class Element extends Node with NodeSelector with ParentNode with NonDo
* automatically. Consequently, there is no need to call several times element.getElementsByTagName with the same
* element and arguments.
*/
def getElementsByTagName(name: String): HTMLCollection = js.native
def getElementsByTagName(name: String): HTMLCollection[Element] = js.native

/** Returns a list of elements with the given tag name belonging to the given namespace. */
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection = js.native
def getElementsByTagNameNS(namespaceURI: String, localName: String): HTMLCollection[Element] = js.native

/** Returns an array-like object of all child elements which have all of the given class names. When called on the
* document object, the complete document is searched, including the root node. You may also call
* getElementsByClassName() on any element; it will return only elements which are descendants of the specified root
* element with the given class names.
*/
def getElementsByClassName(classNames: String): HTMLCollection = js.native
def getElementsByClassName(classNames: String): HTMLCollection[Element] = js.native

/** hasAttributeNS returns a boolean value indicating whether the current element has the specified attribute. */
def hasAttributeNS(namespaceURI: String, localName: String): Boolean = js.native
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/org/scalajs/dom/HTMLCollection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import scala.scalajs.js.annotation._
*/
@js.native
@JSGlobal
class HTMLCollection private[this] () extends DOMList[Element] {
def item(index: Int): Element = js.native
abstract class HTMLCollection[E <: Element] extends DOMList[E] {
def item(index: Int): E = js.native

/** Returns the specific node whose ID or, as a fallback, name matches the string specified by name. Matching by name
* is only done as a last resort, only in HTML, and only if the referenced element supports the name attribute.
* Returns null if no node exists by the given name.
*/
def namedItem(name: String): Element = js.native
def namedItem(name: String): E = js.native
}
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/HTMLDataListElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ import scala.scalajs.js.annotation._
abstract class HTMLDataListElement extends HTMLElement {

/** A collection of the contained option elements. */
def options: HTMLCollection = js.native
def options: HTMLCollection[Element] = js.native
}
12 changes: 6 additions & 6 deletions src/main/scala/org/scalajs/dom/HTMLDocument.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ abstract class HTMLDocument extends Document {
def activeElement: Element = js.native

/** Returns a list of the embedded &lt;embed&gt; elements within the current document. */
def embeds: HTMLCollection = js.native
def embeds: HTMLCollection[Element] = js.native

/** forms returns a collection (an HTMLCollection) of the form elements within the current document. */
def forms: HTMLCollection = js.native
def forms: HTMLCollection[Element] = js.native

/** The links property returns a collection of all AREA elements and anchor elements in a document with a value for
* the href attribute.
*/
def links: HTMLCollection = js.native
def links: HTMLCollection[Element] = js.native

/** anchors returns a list of all of the anchors in the document. */
def anchors: HTMLCollection = js.native
def anchors: HTMLCollection[Element] = js.native

/** Returns an HTMLCollection object containing one or more HTMLEmbedElements or null which represent the
* &lt;embed&gt; elements in the current document.
*/
def plugins: HTMLCollection = js.native
def plugins: HTMLCollection[Element] = js.native

/** document.images returns a collection of the images in the current HTML document. */
def images: HTMLCollection = js.native
def images: HTMLCollection[Element] = js.native

/** Returns the current value of the current range for a formatting command. */
def queryCommandValue(commandId: String): String = js.native
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/HTMLFormElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ abstract class HTMLFormElement extends HTMLElement {
/** elements returns an HTMLFormControlsCollection (HTML 4 HTMLCollection) of all the form controls contained in the
* FORM element, with the exception of input elements which have a type attribute of image.
*/
def elements: HTMLCollection = js.native
def elements: HTMLCollection[Element] = js.native

/** action gets/sets the action of the &lt;form&gt; element. */
var action: String = js.native
Expand Down
18 changes: 18 additions & 0 deletions src/main/scala/org/scalajs/dom/HTMLOptionsCollection.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
* http://creativecommons.org/licenses/by-sa/2.5/
*
* Everything else is under the MIT License http://opensource.org/licenses/MIT
*/
package org.scalajs.dom

import scala.scalajs.js
import scala.scalajs.js.annotation._

/** The HTMLOptionsCollection interface represents a collection of <option> HTML elements (in document order) and offers
* methods and properties for selecting from the list as well as optionally altering its items. This object is returned
* only by the options property of select.
*/
@js.native
@JSGlobal
class HTMLOptionsCollection private[this] () extends HTMLCollection[HTMLOptionElement]
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/HTMLSelectElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.scalajs.js.annotation._
abstract class HTMLSelectElement extends HTMLElement {

/** The set of &lt;option&gt; elements contained by this element. Read only. */
val options: js.Array[HTMLOptionElement] = js.native
val options: HTMLOptionsCollection = js.native

/** The value of this form control, that is, of the first selected option. */
var value: String = js.native
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/org/scalajs/dom/HTMLTableElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class HTMLTableElement extends HTMLElement {
* a &lt;thead&gt; appear first, in tree order, and those members of a &lt;tbody&gt; last, also in tree order. The
* HTMLCollection is live and is automatically updated when the HTMLTableElement changes.
*/
def rows: HTMLCollection = js.native
def rows: HTMLCollection[Element] = js.native

/** Is an HTMLTableCaptionElement representing the first &lt;caption&gt; that is a child of the element, or null if
* none is found. When set, if the object doesn't represent a &lt;caption&gt;, a DOMException with the
Expand All @@ -42,7 +42,7 @@ abstract class HTMLTableElement extends HTMLElement {
/** Returns a live HTMLCollection containing all the &lt;tbody&gt; of the element. The HTMLCollection is live and is
* automatically updated when the HTMLTableElement changes.
*/
def tBodies: HTMLCollection = js.native
def tBodies: HTMLCollection[Element] = js.native

/** Is an HTMLTableSectionElement representing the first &lt;thead&gt; that is a child of the element, or null if none
* is found. When set, if the object doesn't represent a &lt;thead&gt;, a DOMException with the HierarchyRequestError
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/HTMLTableRowElement.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class HTMLTableRowElement extends HTMLElement with HTMLTableAlignment {
/** Returns a live HTMLCollection containing the cells in the row. The HTMLCollection is live and is automatically
* updated when cells are added or removed.
*/
def cells: HTMLCollection = js.native
def cells: HTMLCollection[Element] = js.native

var borderColorLight: js.Any = js.native

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class HTMLTableSectionElement extends HTMLElement with HTMLTableAlignme
/** Returns a live HTMLCollection containing the rows in the section. The HTMLCollection is live and is automatically
* updated when rows are added or removed.
*/
def rows: HTMLCollection = js.native
def rows: HTMLCollection[Element] = js.native

/** Removes the cell at the given position in the section. If the given position is greater (or equal as it starts at
* zero) than the amount of rows in the section, or is smaller than 0, it raises a DOMException with the
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/ParentNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import scala.scalajs.js.|
trait ParentNode extends js.Object {

/** Returns a live HTMLCollection containing all objects of type Element that are children of the object. */
def children: HTMLCollection = js.native
def children: HTMLCollection[Element] = js.native

/** Returns the Element that is the first child of the object, or null if there is none. */
def firstElementChild: Element = js.native
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/html.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object html {
type Button = HTMLButtonElement
type BR = HTMLBRElement
type Canvas = HTMLCanvasElement
type Collection = HTMLCollection
type Collection[E <: Element] = HTMLCollection[E]
type DataList = HTMLDataListElement
type Div = HTMLDivElement
type DList = HTMLDListElement
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/org/scalajs/dom/raw.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ object raw {
type HTMLCanvasElement = dom.HTMLCanvasElement

@deprecated("use dom.HTMLCollectionElement instead", "2.0.0")
type HTMLCollectionElement = dom.HTMLCollection
type HTMLCollectionElement[E <: dom.Element] = dom.HTMLCollection[E]

@deprecated("use dom.HTMLDataListElement instead", "2.0.0")
type HTMLDataListElement = dom.HTMLDataListElement
Expand Down