diff --git a/lib/jsdom/living/nodes/HTMLSelectElement-impl.js b/lib/jsdom/living/nodes/HTMLSelectElement-impl.js index c53251179f..4871061169 100644 --- a/lib/jsdom/living/nodes/HTMLSelectElement-impl.js +++ b/lib/jsdom/living/nodes/HTMLSelectElement-impl.js @@ -90,6 +90,12 @@ class HTMLSelectElementImpl extends HTMLElementImpl { return this.options.length; } + get selectedOptions() { + return createHTMLCollection(this, () => domSymbolTree.treeToArray(this, { filter(node) { + return node._localName === "option" && node._selectedness === true; + } })); + } + get selectedIndex() { return Array.prototype.reduceRight.call(this.options, (prev, option, i) => { option = idlUtils.implForWrapper(option); diff --git a/lib/jsdom/living/nodes/HTMLSelectElement.idl b/lib/jsdom/living/nodes/HTMLSelectElement.idl index 4556875974..39a4f01b6e 100644 --- a/lib/jsdom/living/nodes/HTMLSelectElement.idl +++ b/lib/jsdom/living/nodes/HTMLSelectElement.idl @@ -19,7 +19,7 @@ interface HTMLSelectElement : HTMLElement { void remove(long index); // setter void (unsigned long index, HTMLOptionElement? option); -// [SameObject] readonly attribute HTMLCollection selectedOptions; + [SameObject] readonly attribute HTMLCollection selectedOptions; attribute long selectedIndex; attribute DOMString value; diff --git a/package.json b/package.json index 5dba1666f8..9dca0207be 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "st": "^1.2.0", "watchify": "^3.9.0", "wd": "^1.1.3", - "webidl2js": "^6.0.3" + "webidl2js": "^6.1.0" }, "browser": { "canvas": false, diff --git a/test/web-platform-tests/to-upstream.js b/test/web-platform-tests/to-upstream.js index e775820a00..0732fabaca 100644 --- a/test/web-platform-tests/to-upstream.js +++ b/test/web-platform-tests/to-upstream.js @@ -89,6 +89,7 @@ describe("Local tests in Web Platform Test format (to-upstream)", () => { "html/semantics/forms/the-option-element/option-index.html", "html/semantics/forms/the-option-element/option-element-constructor.html", "html/semantics/forms/the-select-element/select-multiple.html", + "html/semantics/forms/the-select-element/select-selectedOptions.html", "html/semantics/forms/the-textarea-element/select.html", "html/semantics/forms/the-textarea-element/set-value-reset-selection.html", "html/semantics/forms/the-textarea-element/setRangeText.html", diff --git a/test/web-platform-tests/to-upstream/html/semantics/forms/the-select-element/select-selectedOptions.html b/test/web-platform-tests/to-upstream/html/semantics/forms/the-select-element/select-selectedOptions.html new file mode 100644 index 0000000000..f8e577a8a0 --- /dev/null +++ b/test/web-platform-tests/to-upstream/html/semantics/forms/the-select-element/select-selectedOptions.html @@ -0,0 +1,127 @@ + + + + +HTMLSelectElement.selectedOptions + + + + + +
+ + + + + + + + + + + + + + + + + +