commit 43c2affa85b28aa9e05a6eb1b953eb164674867f
parent c2fcf48e758a0b999f57eda59d0fde06eebe45a1
Author: Joey Arhar <jarhar@chromium.org>
Date: Mon, 27 Oct 2025 10:16:44 +0000
Bug 1996342 [wpt PR 55647] - Don't select options when all children are removed, a=testonly
Automatic update from web-platform-tests
Don't select options when all children are removed
This patch fixes a regression caused when moving the calls to
HTMLSelectElement::OptionInserted/OptionRemoved from
HTMLSelectElement::ChildrenChanged to
HTMLOptionElement::InsertedInto/RemovedFrom.
In the pre-regression code path when all options are removed from the
select at once via select.innerHTML = '' for example, the options
selectedness would not be modified because the ResetToDefaultSelection
would only be called once after all the options are removed.
In the post-regression code path, ResetToDefaultSelection is called in
between each option being removed in HTMLOptionElement::RemovedFrom,
which results in every option becoming selected before they are
eventually removed.
This patch replicates the pre-regression behavior by moving calls to
OptionRemoved from HTMLOptionElement::RemovedFrom to
HTMLSelectElement::ChildrenChanged in the case that the option element
is a direct child of the select element.
A better fix might be to always set selectedness to false when an option
is removed from a select element, but that might have other unintended
consequences.
Spec issue: https://github.com/whatwg/html/issues/11825
Fixed: 444330901
Change-Id: I10b7a501993229cccff1e7aa36a7eb306f2da0d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7058561
Reviewed-by: David Baron <dbaron@chromium.org>
Commit-Queue: Joey Arhar <jarhar@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1535201}
--
wpt-commits: 05fa548a743d507924a8e62f17420f1b655419ca
wpt-pr: 55647
Diffstat:
1 file changed, 29 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/tests/html/semantics/forms/the-select-element/select-clear-reappend.tentative.html b/testing/web-platform/tests/html/semantics/forms/the-select-element/select-clear-reappend.tentative.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<link rel=author href="mailto:jarhar@chromium.org">
+<link rel=help href="https://github.com/whatwg/html/issues/11825">
+<link rel=help href="https://issues.chromium.org/issues/444330901">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<select>
+ <option>one</option>
+ <option selected>two</option>
+ <option>three</option>
+</select>
+
+<script>
+test(() => {
+ const select = document.querySelector('select');
+ assert_equals(select.value, 'two',
+ 'two should be selected at the start of the test.');
+
+ const options = document.querySelectorAll('option');
+ select.innerHTML = '';
+ options.forEach(option => {
+ select.appendChild(option);
+ });
+
+ assert_equals(select.value, 'two',
+ 'two should still be selected after clearing and re-appending.');
+}, 'select.value should stay the same after clearing and re-appending options.');
+</script>