diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp index 123edf60f8a..876e2ca15cc 100644 --- a/Libraries/LibWeb/HTML/HTMLOptionElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLOptionElement.cpp @@ -38,6 +38,16 @@ void HTMLOptionElement::initialize(JS::Realm& realm) WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLOptionElement); } +// FIXME: This needs to be called any time a descendant's text is modified. +void HTMLOptionElement::update_selection_label() +{ + if (selected()) { + if (auto* select_element = first_ancestor_of_type()) { + select_element->update_inner_text_element({}); + } + } +} + void HTMLOptionElement::attribute_changed(FlyString const& name, Optional const& old_value, Optional const& value, Optional const& namespace_) { Base::attribute_changed(name, old_value, value, namespace_); @@ -54,6 +64,8 @@ void HTMLOptionElement::attribute_changed(FlyString const& name, Optional()) { - select_element->update_inner_text_element({}); - } - } + // Note: this causes attribute_changed() to be called, which will update the 's label } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-index @@ -240,4 +247,11 @@ void HTMLOptionElement::removed_from(Node* old_parent) } } +void HTMLOptionElement::children_changed() +{ + Base::children_changed(); + + update_selection_label(); +} + } diff --git a/Libraries/LibWeb/HTML/HTMLOptionElement.h b/Libraries/LibWeb/HTML/HTMLOptionElement.h index b6575f31c64..31276174a04 100644 --- a/Libraries/LibWeb/HTML/HTMLOptionElement.h +++ b/Libraries/LibWeb/HTML/HTMLOptionElement.h @@ -52,8 +52,10 @@ private: virtual void inserted() override; virtual void removed_from(Node*) override; + virtual void children_changed() override; void ask_for_a_reset(); + void update_selection_label(); // https://html.spec.whatwg.org/multipage/form-elements.html#concept-option-selectedness bool m_selected { false };