Skip to content

Commit bef9083

Browse files
committed
Define the <selectedoption> element
1 parent 1dc697c commit bef9083

File tree

1 file changed

+204
-22
lines changed

1 file changed

+204
-22
lines changed

source

Lines changed: 204 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,22 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
18071807
</li>
18081808
</ol>
18091809

1810+
<p>The <span data-x="concept-node-post-connection-ext">post-connection steps</span> for the HTML
1811+
Standard, given <var>insertedNode</var>, are defined as the following:</p>
1812+
1813+
<ol>
1814+
<li>
1815+
<p>For each <var>descendant</var> of <var>insertedNode</var>'s <span data-x="inclusive
1816+
descendant">inclusive descendants</span> in <span>tree order</span>:</p>
1817+
1818+
<ol>
1819+
<li><p>If <var>descendant</var> is a <code>selectedoption</code> element, then run the
1820+
<span>selectedoption insertion steps</span> given <var>descendant</var> and
1821+
<var>insertedNode</var>'s <span>parent</span>.</p></li>
1822+
</ol>
1823+
</li>
1824+
</ol>
1825+
18101826
<p>The <span data-x="concept-node-remove-ext">removing steps</span> for the HTML Standard, given
18111827
<var>removedNode</var> and <var>oldParent</var>, are defined as the following:</p>
18121828

@@ -1857,6 +1873,10 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
18571873
<ol>
18581874
<li><p>If <var>descendant</var> is an <code>option</code> element, then run the <span>option
18591875
removal steps</span> given <var>descendant</var> and <var>oldParent</var>.</p></li>
1876+
1877+
<li><p>If <var>descendant</var> is a <code>selectedoption</code> element, then run the
1878+
<span>selectedoption removal steps</span> given <var>descendant</var> and
1879+
<var>oldParent</var>.</p></li>
18601880
</ol>
18611881
</li>
18621882
</ol>
@@ -3222,6 +3242,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
32223242
<li><dfn data-x="dom-Element-id" data-x-href="https://dom.spec.whatwg.org/#dom-element-id"><code>id</code></dfn> attribute</li>
32233243
<li><dfn data-x="dom-Element-setAttribute" data-x-href="https://dom.spec.whatwg.org/#dom-element-setattribute"><code>setAttribute()</code></dfn> method</li>
32243244
<li><dfn data-x-href="https://dom.spec.whatwg.org/#dom-node-textcontent"><code>textContent</code></dfn> attribute</li>
3245+
<li><dfn data-x="dom-parentnode-replacechildren" data-x-href="https://dom.spec.whatwg.org/#dom-parentnode-replacechildren"><code>replaceChildren()</code></dfn> method</li>
32253246

32263247
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#concept-tree">tree</dfn>, <dfn data-x-href="https://dom.spec.whatwg.org/#concept-shadow-tree">shadow tree</dfn>, and <dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-tree">node tree</dfn> concepts</li>
32273248
<li>The <dfn data-x-href="https://dom.spec.whatwg.org/#concept-tree-order">tree order</dfn> and <dfn data-x-href="https://dom.spec.whatwg.org/#concept-shadow-including-tree-order">shadow-including tree order</dfn> concepts</li>
@@ -3257,6 +3278,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
32573278
<li>The <dfn data-x="concept-tree-descendant" data-x-href="https://dom.spec.whatwg.org/#concept-tree-descendant">descendant</dfn> concept</li>
32583279
<li>The <dfn data-x="concept-node-insert-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-insert-ext">insertion steps</dfn>,
32593280
<dfn data-x="concept-node-remove-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-remove-ext">removing steps</dfn>,
3281+
<dfn data-x="concept-node-post-connection-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-post-connection-ext">post-connection steps</dfn>,
32603282
<dfn data-x="concept-node-adopt-ext" data-x-href="https://dom.spec.whatwg.org/#concept-node-adopt-ext">adopting steps</dfn>, and
32613283
<dfn data-x-href="https://dom.spec.whatwg.org/#concept-node-children-changed-ext">children changed steps</dfn> hooks for elements</li>
32623284
<li>The <dfn data-x="concept-element-attributes-change" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-change">change</dfn>, <dfn data-x="concept-element-attributes-append" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-append">append</dfn>, <dfn data-x="concept-element-attributes-remove" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove">remove</dfn>, <dfn data-x="concept-element-attributes-replace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-replace">replace</dfn>, <dfn data-x="concept-element-attributes-get-by-namespace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-get-by-namespace">get an attribute by namespace and local name</dfn>, <dfn data-x="concept-element-attributes-set-value" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-set-value">set value</dfn>, and <dfn data-x="concept-element-attributes-remove-by-namespace" data-x-href="https://dom.spec.whatwg.org/#concept-element-attributes-remove-by-namespace">remove an attribute by namespace and local name</dfn> algorithms for attributes</li>
@@ -3344,6 +3366,7 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
33443366
<li><dfn data-x="mo childList" data-x-href="https://dom.spec.whatwg.org/#dom-mutationobserverinit-childlist"><code>childList</code></dfn></li>
33453367
<li><dfn data-x="mo characterData" data-x-href="https://dom.spec.whatwg.org/#dom-mutationobserverinit-characterdata"><code>characterData</code></dfn></li>
33463368
<li><dfn data-x="mo subtree" data-x-href="https://dom.spec.whatwg.org/#dom-mutationobserverinit-subtree"><code>subtree</code></dfn></li>
3369+
<li><dfn data-x="mo attributes" data-xhref="https://dom.spec.whatwg.org/#dom-mutationobserverinit-attributes"><code>attributes</code></dfn></li>
33473370
<li><dfn data-x-href="https://dom.spec.whatwg.org/#abortcontroller"><code>AbortController</code></dfn> and its
33483371
<dfn data-x="concept-AbortController-signal" data-x-href="https://dom.spec.whatwg.org/#abortcontroller-signal">signal</dfn></li>
33493372
<li><dfn data-x-href="https://dom.spec.whatwg.org/#abortsignal"><code>AbortSignal</code></dfn></li>
@@ -53424,6 +53447,9 @@ interface <dfn interface>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
5342453447
<li><p>Return <var>options</var>.</p></li>
5342553448
</ol>
5342653449

53450+
<p>Every <code>select</code> element has <dfn>select descendant selectedoption elements</dfn>,
53451+
which is a <span>list</span> of <code>selectedoption</code> elements, initially « ».</p>
53452+
5342753453
<p>The <dfn element-attr for="select"><code data-x="attr-select-required">required</code></dfn>
5342853454
attribute is a <span>boolean attribute</span>. When specified, the user will be required to select
5342953455
a value before submitting the form.</p>
@@ -53470,10 +53496,23 @@ interface <dfn interface>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
5347053496
through a click, or through unfocusing the element after changing its value, or through a <span
5347153497
data-x="option-command">menu command</span>, or through any other mechanism), and before the
5347253498
relevant user interaction event <!-- interaction event spec point --> is queued (e.g. before the
53473-
<code data-x="event-click">click</code> event), the user agent must set the <span
53474-
data-x="concept-option-selectedness">selectedness</span> of the picked <code>option</code> element
53475-
to true, set its <span data-x="concept-option-dirtiness">dirtiness</span> to true, and then
53476-
<span>send <code>select</code> update notifications</span>.</p>
53499+
<code data-x="event-click">click</code> event), the user agent must run the following steps given
53500+
the <code>select</code> <var>select</var> and the picked <code>option</code>
53501+
<var>option</var>:</p>
53502+
53503+
<ol>
53504+
<li><p>Set the <span data-x="concept-option-selectedness">selectedness</span> of
53505+
<var>option</var> to true.</p></li>
53506+
53507+
<li><p>Set the <span data-x="concept-option-dirtiness">dirtiness</span> of <var>option</var> to
53508+
true.</p></li>
53509+
53510+
<li><p><span>Send <code>select</code> update notifications</span>.</p></li>
53511+
53512+
<li><p>For each <var>selectedoption</var> in <var>select</var>'s <span>select descendant
53513+
selectedoption elements</span>, run <span>clone an option into a selectedoption</span> given
53514+
<var>option</var> and <var>selectedoption</var>.</p></li>
53515+
</ol>
5347753516

5347853517
<p>If the <code data-x="attr-select-multiple">multiple</code> attribute is absent, whenever an
5347953518
<code>option</code> element in the <code>select</code> element's <span
@@ -53502,23 +53541,33 @@ interface <dfn interface>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
5350253541

5350353542
<ol>
5350453543
<li><p>If <var>element</var>'s <code data-x="attr-select-multiple">multiple</code> attribute is
53505-
absent, and <var>element</var>'s <span data-x="concept-select-size">display size</span> is 1,
53506-
and no <code>option</code> elements in the <var>element</var>'s <span
53544+
absent, then return.</p></li>
53545+
53546+
<li><p>If <var>element</var>'s <span data-x="concept-select-size">display size</span> is 1, and
53547+
no <code>option</code> elements in the <var>element</var>'s <span
5350753548
data-x="concept-select-option-list">list of options</span> have their <span
5350853549
data-x="concept-option-selectedness">selectedness</span> set to true, then set the <span
53509-
data-x="concept-option-selectedness">selectedness</span> of the first <code>option</code>
53510-
element in the <span data-x="concept-select-option-list">list of options</span> in
53511-
<span>tree order</span> that is not <span data-x="concept-option-disabled">disabled</span>,
53512-
if any, to true, and return.</p></li>
53550+
data-x="concept-option-selectedness">selectedness</span> of the first <code>option</code> element
53551+
in the <span data-x="concept-select-option-list">list of options</span> in <span>tree
53552+
order</span> that is not <span data-x="concept-option-disabled">disabled</span>, if any, to true,
53553+
and return.</p></li>
5351353554

53514-
<li><p>If <var>element</var>'s <code data-x="attr-select-multiple">multiple</code> attribute is
53515-
absent, and two or more <code>option</code> elements in <var>element</var>'s <span
53555+
<li><p>If two or more <code>option</code> elements in <var>element</var>'s <span
5351653556
data-x="concept-select-option-list">list of options</span> have their <span
5351753557
data-x="concept-option-selectedness">selectedness</span> set to true, then set the <span
5351853558
data-x="concept-option-selectedness">selectedness</span> of all but the last <code>option</code>
5351953559
element with its <span data-x="concept-option-selectedness">selectedness</span> set to true in
5352053560
the <span data-x="concept-select-option-list">list of options</span> in <span>tree order</span>
5352153561
to false.</p></li>
53562+
53563+
<li><p>Let <var>option</var> be the first <code>option</code> in <var>element</var>'s <span
53564+
data-x="concept-select-option-list">list of options</span> which has its <span
53565+
data-x="concept-option-selectedness">selectedness</span> set to true, or null if there is no such
53566+
<code>option</code>.</p></li>
53567+
53568+
<li><p>For each <var>selectedoption</var> in <var>element</var>'s <span>select descendant
53569+
selectedoption elements</span>, run <span>clone an option into a selectedoption</span> given
53570+
<var>option</var> and <var>selectedoption</var>.</p></li>
5352253571
</ol>
5352353572

5352453573
<p>The <dfn>option insertion steps</dfn>, given <var>option</var> and <var>insertionPoint</var>,
@@ -53837,14 +53886,27 @@ interface <dfn interface>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
5383753886
data-x="concept-option-selectedness">selectedness</span> set to true, if any. If there isn't one,
5383853887
then it must return the empty string.</p>
5383953888

53840-
<p>On setting, the <code data-x="dom-select-value">value</code> attribute must set the <span
53841-
data-x="concept-option-selectedness">selectedness</span> of all the <code>option</code> elements
53842-
in the <span data-x="concept-select-option-list">list of options</span> to false, and then the
53843-
first <code>option</code> element in the <span data-x="concept-select-option-list">list of
53844-
options</span>, in <span>tree order</span>, whose <span data-x="concept-option-value">value</span>
53845-
is equal to the given new value, if any, must have its <span
53846-
data-x="concept-option-selectedness">selectedness</span> set to true and its <span
53847-
data-x="concept-option-dirtiness">dirtiness</span> set to true.</p>
53889+
<p>On setting, the <code data-x="dom-select-value">value</code> attribute must run the following
53890+
steps:</p>
53891+
53892+
<ol>
53893+
<li><p>Set the <span data-x="concept-option-selectedness">selectedness</span> of all the
53894+
<code>option</code> elements in the <span data-x="concept-select-option-list">list of
53895+
options</span> to false</p></li>
53896+
53897+
<li><p>Let <var>option</var> be the first <code>option</code> element in the <span
53898+
data-x="concept-select-option-list">list of options</span> in <span>tree order</span> whose <span
53899+
data-x="concept-option-value">value</span> is equal to the new given value, otherwise
53900+
null.</p></li>
53901+
53902+
<li><p>If <var>option</var> is not null, then set <var>option</var>'s <span
53903+
data-x="concept-option-selectedness">selectedness</span> to true and its <span
53904+
data-x="concept-option-dirtiness">dirtiness</span> to true.
53905+
53906+
<li><p>For each <var>selectedoption</var> in <var>select</var>'s <span>select descendant
53907+
selectedoption elements</span>, run <span>clone an option into a selectedoption</span> given
53908+
<var>option</var> and <var>selectedoption</var>.</p></li>
53909+
</ol>
5384853910

5384953911
<p class="note">This can result in no element having a <span
5385053912
data-x="concept-option-selectedness">selectedness</span> set to true even in the case of the
@@ -54363,6 +54425,16 @@ interface <dfn interface>HTMLOptionElement</dfn> : <span>HTMLElement</span> {
5436354425
<span>drop-down box</span>, then set <var>select</var>'s <span>select fallback
5436454426
button text</span> to the value of <var>option</var>'s <span
5436554427
data-x="dom-option-label">label</span>.</p></li>
54428+
54429+
<li>
54430+
<p>For each <var>selectedoption</var> of <var>select</var>'s <span>select descendant
54431+
selectedoption elements</span>:</p>
54432+
54433+
<ol>
54434+
<li><p>Run <span>clone an option into a selectedoption</span> given <var>option</var> and
54435+
<var>selectedoption</var>.</p></li>
54436+
</ol>
54437+
</li>
5436654438
</ol>
5436754439

5436854440
<p>The <code>option</code> <span>HTML element insertion steps</span>, given
@@ -54372,8 +54444,9 @@ interface <dfn interface>HTMLOptionElement</dfn> : <span>HTMLElement</span> {
5437254444
<li><p>Run the <span>mutation observer observe algorithm</span> given <var>insertedOption</var>'s
5437354445
<span>option element mutation observer</span>, <var>insertedOption</var>, and a
5437454446
<code>MutationObserverInit</code> with <code data-x="mo characterData">characterData</code> set
54375-
to true, <code data-x="mo childList">childList</code> set to true, and <code data-x="mo
54376-
subtree">subtree</code> set to true.</p></li>
54447+
to true, <code data-x="mo childList">childList</code> set to true, <code data-x="mo
54448+
subtree">subtree</code> set to true, and <code data-x="mo attributes">attributes</code> set to
54449+
true.</p></li>
5437754450
</ol>
5437854451

5437954452
<p>The <code>option</code> <span>HTML element removing steps</span>, given
@@ -56073,6 +56146,115 @@ interface <dfn interface>HTMLLegendElement</dfn> : <span>HTMLElement</span> {
5607356146

5607456147
</div>
5607556148

56149+
<h4>The <dfn element><code>selectedoption</code></dfn> element</h4>
56150+
56151+
<p>The <code>selectedoption</code> element reflects the contents of a <code>select</code>
56152+
element's currently selected <code>option</code> element. <code>selectedoption</code> elements can
56153+
be used to declaratively show the selected <code>option</code> element's contents in a different
56154+
part of the document, such as the <code>select</code> element's invoker button, with alternate
56155+
rendering based on different selectors in the author's stylesheet.</p>
56156+
56157+
<p>Every time the selected <code>option</code> of a <code>select</code> switches from one option
56158+
to another, or the currently selected <code>option</code>'s descendant DOM structure mutates, the
56159+
<code>selectedoption</code> element removes all of its children and replaces them with a new
56160+
cloned copy of the DOM structure of the <code>select</code>'s selected <code>option</code>
56161+
element.</p>
56162+
56163+
<p><code>selectedoption</code> elements become associated with <code>select</code> elements when
56164+
the <code>selectedoption</code> is a <span>descendant</span> of the <code>select</code>.</p>
56165+
56166+
<!-- TODO add code example(s) -->
56167+
56168+
<p>To <dfn>clone an option into a selectedoption</dfn>, given an <code>option</code> element
56169+
<var>option</var> and a <code>selectedoption</code> element <var>selectedOption</var>:</p>
56170+
56171+
<ol>
56172+
<li><p>Let <var>nodes</var> be « ».</p></li>
56173+
56174+
<li>
56175+
<p>If <var>option</var> is not null, then for each <var>child</var> of <var>option</var>'s <span
56176+
data-x="concept-tree-child">children</span>:</p>
56177+
56178+
<ol>
56179+
<li><p>Let <var>childClone</var> be the result of running <span
56180+
data-x="concept-node-clone">clone</span> given <var>child</var>, null, true.</p></li>
56181+
56182+
<li><p><span data-x="list append">Append</span> <var>childClone</var> to
56183+
<var>nodes</var>.</p></li>
56184+
</ol>
56185+
</li>
56186+
56187+
<li><p>Run <span data-x="dom-parentnode-replacechildren">replaceChildren</span> on
56188+
<var>selectedOption</var> given <var>nodes</var>.</p></li>
56189+
</ol>
56190+
56191+
<p>The <dfn>selectedoption insertion steps</dfn>, given <var>selectedoption</var> and
56192+
<var>insertionPoint</var>, are:</p>
56193+
56194+
<ol>
56195+
<li><p>Let <var>firstAncestorSelect</var> be null.</p></li>
56196+
56197+
<li><p>Let <var>ancestor</var> be <var>selectedoption</var>'s <span>parent</span>.</p></li>
56198+
56199+
<li>
56200+
<p><span>While</span> <var>firstAncestorSelect</var> is null and <var>ancestor</var> is not
56201+
null:</p>
56202+
56203+
<ol>
56204+
<li><p>If <var>ancestor</var> is a <code>select</code> element, then set
56205+
<var>firstAncestorSelect</var> to <var>ancestor</var>.</p></li>
56206+
56207+
<li><p>Set <var>ancestor</var> to <var>ancestor</var>'s <span>parent</span>.</p></li>
56208+
</ol>
56209+
</li>
56210+
56211+
<li><p>If <var>firstAncestorSelect</var> is null, then return.</p></li>
56212+
56213+
<li><p><span data-x="list append">Append</span> <var>selectedoption</var> to
56214+
<var>firstAncestorSelect</var>'s <span>select descendant selectedoption elements</span>.</p></li>
56215+
56216+
<li><p>Run <span>clone an option into a selectedoption</span> given the first <code>option</code>
56217+
in <var>firstAncestorSelect</var>'s <span data-x="concept-select-option-list">list of
56218+
options</span> whose <span data-x="concept-option-selectedness">selectedness</span> is true and
56219+
<var>insertedNode</var>.</p></li>
56220+
</ol>
56221+
56222+
<p>The <dfn>selectedoption removal steps</dfn>, given <var>selectedoption</var> and
56223+
<var>oldParent</var>, are:</p>
56224+
56225+
<ol>
56226+
<li>
56227+
<p>For each <var>ancestor</var> of <var>selectedoption</var>'s <span
56228+
data-x="ancestor">ancestors</span>:</p>
56229+
56230+
<ol>
56231+
<li><p>If <var>ancestor</var> is a <code>select</code> element, then return.</p></li>
56232+
</ol>
56233+
</li>
56234+
56235+
<li>
56236+
<p>For each <var>ancestor</var> of <var>oldParent</var>'s <span data-x="inclusive
56237+
ancestor">inclusive ancestors</span>:</p>
56238+
56239+
<ol>
56240+
<li>
56241+
<p>If <var>ancestor</var> is a <code>select</code> element, then:</p>
56242+
56243+
<ol>
56244+
<li><p><span data-x="list remove">remove</span> <var>selectedoption</var> from
56245+
<var>ancestor</var>'s <span>select descendant selectedoption elements</span>.</p></li>
56246+
56247+
<li><p>Run <span>clone an option into a selectedoption</span> given null and
56248+
<var>selectedoption</var>.</p></li>
56249+
56250+
<li><p>Return.</p></li>
56251+
</ol>
56252+
</li>
56253+
</ol>
56254+
</li>
56255+
</ol>
56256+
56257+
<!-- TODO: call the thing during selectedness setting algorithm and mutationobserver. -->
5607656258

5607756259

5607856260
<h4 split-filename="form-control-infrastructure">Form control infrastructure</h4>

0 commit comments

Comments
 (0)