-
Notifications
You must be signed in to change notification settings - Fork 3k
Description
What is the issue with the HTML Standard?
Consider the following:
<select id=select>
<option id=one>one</option>
<option id=two>two</option>
</select>
<script>
const one = document.getElementById('one');
const two = document.getElementById('two');
select.innerHTML = '';
select.appendChild(one);
select.appendChild(two);
console.log(select.value);
</script>In webkit, "one" is the selected option. In firefox, "two" is the selected option. In chromium, it used to be "one" until I unknowingly changed it to "two", and now I have to change it back to the webkit behavior of "one" due to a regression affecting multiple sites.
In webkit and pre-regression chromium:
The selectedness setting algorithm runs after all of the options are removed in HTMLSelectElement::ChildrenChanged, so option one stays selected and option two stays not-selected.
In firefox, which I think matches the spec as well:
The selectedness setting algorithm runs in between option removals, which means that one gets removed and stays selected, then the selectedness setting algorithm makes option two selected, then option two gets removed and stays selected. When the options are re-appended, inserting option two which is selected causes option one to become un-selected.
I don't think that there is a spec equivalent of the chromium/webkit ChildrenChanged with kAllChildrenRemoved which allows us to run something after all of the children have been removed from the select element, is there?
Another idea I had to fix this was to just set selection back to an initial state any time an option element gets removed, meaning that it selectedness gets set to true if it has the selected attribute, otherwise false. However I'm hesitant to do this in case it breaks more sites.