diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index e2216472cc4..d7001e33f24 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -133,7 +133,16 @@ HTMLOptionElement* HTMLSelectElement::named_item(FlyString const& name) WebIDL::ExceptionOr HTMLSelectElement::add(HTMLOptionOrOptGroupElement element, Optional before) { // Similarly, the add(element, before) method must act like its namesake method on that same options collection. - return const_cast(*options()).add(move(element), move(before)); + TRY(const_cast(*options()).add(move(element), move(before))); + + // If the inserted element is the first and only element, mark it as selected + auto options = list_of_options(); + if (options.size() == 1) { + options.at(0)->set_selected(true); + update_inner_text_element(); + } + + return {}; } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-remove