Skip to content

Commit 50d6d4f

Browse files
authored
Improve option insertion and removal algorithms
This PR improves the option element insertion and removal steps to incorporate invalid nestings of option elements inside select elements by reusing the nearest ancestor select algorithm. It also adds datalist to the list of disallowed elements for nesting options in. Fixes #11787.
1 parent 24fcc03 commit 50d6d4f

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

source

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56210,6 +56210,8 @@ interface <dfn interface>HTMLSelectElement</dfn> : <span>HTMLElement</span> {
5621056210

5621156211
<li><p><var>node</var> is an <code>option</code> element;</p></li>
5621256212

56213+
<li><p><var>node</var> is a <code>datalist</code> element;</p></li>
56214+
5621356215
<li><p><var>node</var> is an <code>optgroup</code> element and <var>node</var> has an
5621456216
<span>ancestor</span> <code>optgroup</code> in between itself and <var>select</var>,</p></li>
5621556217
</ul>
@@ -57001,8 +57003,8 @@ interface <dfn interface>HTMLOptionElement</dfn> : <span>HTMLElement</span> {
5700157003
in reverse <span>tree order</span>:</p>
5700257004

5700357005
<ol>
57004-
<li><p>If <var>ancestor</var> is a <code>select</code>, <code>hr</code>, or <code>option</code>
57005-
element, then return false.</p></li>
57006+
<li><p>If <var>ancestor</var> is a <code>select</code>, <code>hr</code>, <code>datalist</code>,
57007+
or <code>option</code> element, then return false.</p></li>
5700657008

5700757009
<li><p>If <var>ancestor</var> is an <code>optgroup</code> element, then return true if
5700857010
<var>ancestor</var>'s <code data-x="attr-optgroup-disabled">disabled</code> attribute is
@@ -57098,50 +57100,54 @@ interface <dfn interface>HTMLOptionElement</dfn> : <span>HTMLElement</span> {
5709857100

5709957101
</div>
5710057102

57103+
<p>Each <code>option</code> element has a <dfn>cached nearest ancestor <code>select</code>
57104+
element</dfn>, which is a <code>select</code> element or null, initially set to null.</p>
57105+
5710157106
<div algorithm>
57102-
<p>The <code>option</code> <span>HTML element insertion steps</span>, given
57103-
<var>insertedOption</var>, are:</p>
57107+
<p>To <dfn>update an <code>option</code>'s nearest ancestor <code>select</code></dfn>, given an
57108+
<code>option</code> <var>option</var>:</p>
5710457109

5710557110
<ol>
57111+
<li><p>Let <var>oldSelect</var> be <var>option</var>'s <span>cached nearest ancestor
57112+
<code>select</code> element</span>.</p></li>
57113+
57114+
<li><p>Let <var>newSelect</var> be <var>option</var>'s <span><code>option</code> element
57115+
nearest ancestor <code>select</code></span>.</p></li>
57116+
5710657117
<li>
57107-
<p>For each <var>ancestor</var> of <var>insertedOption</var>'s <span
57108-
data-x="ancestor">ancestors</span> in reverse <span>tree order</span>:</p>
57118+
<p>If <var>oldSelect</var> is not <var>newSelect</var>:</p>
5710957119

5711057120
<ol>
57111-
<li><p>If <var>ancestor</var> is a <code>select</code> element, then run the <span>selectedness
57112-
setting algorithm</span> given <var>ancestor</var> and return.</p></li>
57121+
<li><p>If <var>oldSelect</var> is not null, then run the <span>selectedness setting
57122+
algorithm</span> given <var>oldSelect</var>.</p></li>
57123+
57124+
<li><p>If <var>newSelect</var> is not null, then run the <span>selectedness setting
57125+
algorithm</span> given <var>newSelect</var>.</p></li>
5711357126
</ol>
5711457127
</li>
57128+
57129+
<li><p>Set <var>option</var>'s <span>cached nearest ancestor <code>select</code>
57130+
element</span> to <var>newSelect</var>.<p></li>
5711557131
</ol>
5711657132
</div>
5711757133

5711857134
<div algorithm>
57119-
<p>The <code>option</code> <span>HTML element removing steps</span>, given
57120-
<var>removedOption</var> and <var>oldParent</var>, are:</p>
57121-
57122-
<ol>
57123-
<li>
57124-
<p>For each <var>ancestor</var> of <var>oldParent</var>'s <span data-x="inclusive
57125-
ancestor">inclusive ancestors</span> in reverse <span>tree order</span>:</p>
57135+
<p>The <code>option</code> <span>HTML element insertion steps</span>, given
57136+
<var>insertedOption</var>, are to run <span>update an <code>option</code>'s nearest ancestor
57137+
<code>select</code></span> given <var>insertedOption</var>.</p>
57138+
</div>
5712657139

57127-
<ol>
57128-
<li><p>If <var>ancestor</var> is a <code>select</code> element, then run the <span>selectedness
57129-
setting algorithm</span> given <var>ancestor</var> and return.</p></li>
57130-
</ol>
57131-
</ol>
57140+
<div algorithm>
57141+
<p>The <code>option</code> <span>HTML element removing steps</span>, given
57142+
<var>removedOption</var> and <var>oldParent</var>, are to run <span>update an
57143+
<code>option</code>'s nearest ancestor <code>select</code></span> given
57144+
<var>removedOption</var>.</p>
5713257145
</div>
5713357146

5713457147
<div algorithm>
5713557148
<p>The <code>option</code> <span>HTML element moving steps</span>, given <var>movedNode</var> and
57136-
<var>oldParent</var>, are:</p>
57137-
57138-
<ol>
57139-
<li><p>Run the <code>option</code> <span>HTML element removing steps</span> given
57140-
<var>movedNode</var> and <var>oldParent</var>.</p></li>
57141-
57142-
<li><p>Run the <code>option</code> <span>HTML element insertion steps</span> given
57143-
<var>movedNode</var>.</p></li>
57144-
</ol>
57149+
<var>oldParent</var>, are to run <span>update an <code>option</code>'s nearest ancestor
57150+
<code>select</code></span> given <var>movedNode</var>.</p>
5714557151
</div>
5714657152

5714757153
<div algorithm>

0 commit comments

Comments
 (0)