Skip to content

Commit 3d1f149

Browse files
committed
Create HTMLOptionsCollection to improve ux when dealing with <select><option>
1 parent 3ae10e1 commit 3d1f149

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

api-reports/2_12.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9187,6 +9187,10 @@ HTMLOptionElement[JC] var text: String
91879187
HTMLOptionElement[JC] var textContent: String
91889188
HTMLOptionElement[JC] var title: String
91899189
HTMLOptionElement[JC] var value: String
9190+
HTMLOptionsCollection[JC] @JSBracketAccess def apply(index: Int): T
9191+
HTMLOptionsCollection[JC] def item(index: Int): HTMLOptionElement
9192+
HTMLOptionsCollection[JC] def length: Int
9193+
HTMLOptionsCollection[JC] def namedItem(name: String): HTMLOptionElement
91909194
HTMLParagraphElement[JC] var accessKey: String
91919195
HTMLParagraphElement[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
91929196
HTMLParagraphElement[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -10552,7 +10556,7 @@ HTMLSelectElement[JC] var ontimeupdate: js.Function1[Event, _]
1055210556
HTMLSelectElement[JC] var onvolumechange: js.Function1[Event, _]
1055310557
HTMLSelectElement[JC] var onwaiting: js.Function1[Event, _]
1055410558
HTMLSelectElement[JC] var onwheel: js.Function1[WheelEvent, _]
10555-
HTMLSelectElement[JC] val options: js.Array[HTMLOptionElement]
10559+
HTMLSelectElement[JC] val options: HTMLOptionsCollection
1055610560
HTMLSelectElement[JC] var outerHTML: String
1055710561
HTMLSelectElement[JC] def ownerDocument: Document
1055810562
HTMLSelectElement[JC] override def ownerDocument: HTMLDocument

api-reports/2_13.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9187,6 +9187,10 @@ HTMLOptionElement[JC] var text: String
91879187
HTMLOptionElement[JC] var textContent: String
91889188
HTMLOptionElement[JC] var title: String
91899189
HTMLOptionElement[JC] var value: String
9190+
HTMLOptionsCollection[JC] @JSBracketAccess def apply(index: Int): T
9191+
HTMLOptionsCollection[JC] def item(index: Int): HTMLOptionElement
9192+
HTMLOptionsCollection[JC] def length: Int
9193+
HTMLOptionsCollection[JC] def namedItem(name: String): HTMLOptionElement
91909194
HTMLParagraphElement[JC] var accessKey: String
91919195
HTMLParagraphElement[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit
91929196
HTMLParagraphElement[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit
@@ -10552,7 +10556,7 @@ HTMLSelectElement[JC] var ontimeupdate: js.Function1[Event, _]
1055210556
HTMLSelectElement[JC] var onvolumechange: js.Function1[Event, _]
1055310557
HTMLSelectElement[JC] var onwaiting: js.Function1[Event, _]
1055410558
HTMLSelectElement[JC] var onwheel: js.Function1[WheelEvent, _]
10555-
HTMLSelectElement[JC] val options: js.Array[HTMLOptionElement]
10559+
HTMLSelectElement[JC] val options: HTMLOptionsCollection
1055610560
HTMLSelectElement[JC] var outerHTML: String
1055710561
HTMLSelectElement[JC] def ownerDocument: Document
1055810562
HTMLSelectElement[JC] override def ownerDocument: HTMLDocument
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/** All documentation for facades is thanks to Mozilla Contributors at https://developer.mozilla.org/en-US/docs/Web/API
2+
* and available under the Creative Commons Attribution-ShareAlike v2.5 or later.
3+
* http://creativecommons.org/licenses/by-sa/2.5/
4+
*
5+
* Everything else is under the MIT License http://opensource.org/licenses/MIT
6+
*/
7+
package org.scalajs.dom
8+
9+
import scala.scalajs.js
10+
import scala.scalajs.js.annotation._
11+
12+
/** The HTMLOptionsCollection interface represents a collection of <option> HTML elements (in document order) and offers
13+
* methods and properties for selecting from the list as well as optionally altering its items. This object is returned
14+
* only by the options property of select.
15+
*/
16+
@js.native
17+
@JSGlobal
18+
class HTMLOptionsCollection private[this] () extends DOMList[HTMLOptionElement] {
19+
def item(index: Int): HTMLOptionElement = js.native
20+
21+
/** Returns the specific node whose ID or, as a fallback, name matches the string specified by name. Matching by name
22+
* is only done as a last resort, only in HTML, and only if the referenced element supports the name attribute.
23+
* Returns null if no node exists by the given name.
24+
*/
25+
def namedItem(name: String): HTMLOptionElement = js.native
26+
}

src/main/scala/org/scalajs/dom/HTMLSelectElement.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import scala.scalajs.js.annotation._
1717
abstract class HTMLSelectElement extends HTMLElement {
1818

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

2222
/** The value of this form control, that is, of the first selected option. */
2323
var value: String = js.native

0 commit comments

Comments
 (0)