diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs
index 55ffa92257b..f5256e71b70 100644
--- a/components/script/dom/htmloptgroupelement.rs
+++ b/components/script/dom/htmloptgroupelement.rs
@@ -135,8 +135,8 @@ impl VirtualMethods for HTMLOptGroupElement {
}
fn bind_to_tree(&self, context: &BindContext, can_gc: CanGc) {
- if let Some(s) = self.super_type() {
- s.bind_to_tree(context, can_gc);
+ if let Some(super_type) = self.super_type() {
+ super_type.bind_to_tree(context, can_gc);
}
self.update_select_validity(can_gc);
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index b573388c73a..800e88f0758 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -29,7 +29,7 @@ use crate::dom::htmlformelement::HTMLFormElement;
use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
use crate::dom::htmlscriptelement::HTMLScriptElement;
use crate::dom::htmlselectelement::HTMLSelectElement;
-use crate::dom::node::{BindContext, Node, ShadowIncluding, UnbindContext};
+use crate::dom::node::{BindContext, ChildrenMutation, Node, ShadowIncluding, UnbindContext};
use crate::dom::text::Text;
use crate::dom::validation::Validatable;
use crate::dom::validitystate::ValidationFlags;
@@ -380,4 +380,26 @@ impl VirtualMethods for HTMLOptionElement {
el.check_disabled_attribute();
}
}
+
+ fn children_changed(&self, mutation: &ChildrenMutation) {
+ if let Some(super_type) = self.super_type() {
+ super_type.children_changed(mutation);
+ }
+
+ // Changing the descendants of a selected option can change it's displayed label
+ // if it does not have a label attribute
+ if !self
+ .upcast::()
+ .has_attribute(&local_name!("label"))
+ {
+ if let Some(owner_select) = self.owner_select_element() {
+ if owner_select
+ .selected_option()
+ .is_some_and(|selected_option| self == &*selected_option)
+ {
+ owner_select.update_shadow_tree(CanGc::note());
+ }
+ }
+ }
+ }
}
diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs
index f4a62abe8b4..56fac20e841 100644
--- a/components/script/dom/htmlselectelement.rs
+++ b/components/script/dom/htmlselectelement.rs
@@ -153,7 +153,7 @@ impl HTMLSelectElement {
n
}
- // https://html.spec.whatwg.org/multipage/#concept-select-option-list
+ ///
pub(crate) fn list_of_options(
&self,
) -> impl Iterator- > + use<'_> {
@@ -353,8 +353,10 @@ impl HTMLSelectElement {
.fire_bubbling_event(atom!("change"), can_gc);
}
- fn selected_option(&self) -> Option> {
- self.list_of_options().find(|opt_elem| opt_elem.Selected())
+ pub(crate) fn selected_option(&self) -> Option> {
+ self.list_of_options()
+ .find(|opt_elem| opt_elem.Selected())
+ .or_else(|| self.list_of_options().next())
}
pub(crate) fn show_menu(&self, can_gc: CanGc) -> Option {
@@ -539,7 +541,8 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
///
fn Value(&self) -> DOMString {
- self.selected_option()
+ self.list_of_options()
+ .find(|opt_elem| opt_elem.Selected())
.map(|opt_elem| opt_elem.Value())
.unwrap_or_default()
}
diff --git a/tests/wpt/meta/html/rendering/replaced-elements/the-select-element/select-1-block-size.html.ini b/tests/wpt/meta/html/rendering/replaced-elements/the-select-element/select-1-block-size.html.ini
deleted file mode 100644
index 706aff5771a..00000000000
--- a/tests/wpt/meta/html/rendering/replaced-elements/the-select-element/select-1-block-size.html.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[select-1-block-size.html]
- expected: FAIL
diff --git a/tests/wpt/meta/html/rendering/replaced-elements/the-select-element/select-multiple-re-add-option-via-document-fragment.html.ini b/tests/wpt/meta/html/rendering/replaced-elements/the-select-element/select-multiple-re-add-option-via-document-fragment.html.ini
deleted file mode 100644
index bacaac5e98d..00000000000
--- a/tests/wpt/meta/html/rendering/replaced-elements/the-select-element/select-multiple-re-add-option-via-document-fragment.html.ini
+++ /dev/null
@@ -1,2 +0,0 @@
-[select-multiple-re-add-option-via-document-fragment.html]
- expected: FAIL