From 86859b77a20821eac419902d3ba30b3def149676 Mon Sep 17 00:00:00 2001 From: Psychpsyo Date: Mon, 3 Feb 2025 16:57:27 +0100 Subject: [PATCH] LibWeb: Hide hidden select children from dropdown --- Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 29 ++++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index a334f574c5b..216635490b7 100644 --- a/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -463,25 +463,28 @@ void HTMLSelectElement::show_the_picker_if_applicable() m_select_items.clear(); u32 id_counter = 1; for (auto const& child : children_as_vector()) { - if (is(*child)) { - auto& opt_group_element = as(*child); - Vector option_group_items; - for (auto const& child : opt_group_element.children_as_vector()) { - if (is(*child)) { - auto& option_element = as(*child); - option_group_items.append(SelectItemOption { id_counter++, option_element.selected(), option_element.disabled(), option_element, strip_newlines(option_element.label()), option_element.value() }); + if (auto const* opt_group_element = as_if(*child)) { + if (!opt_group_element->has_attribute(Web::HTML::AttributeNames::hidden)) { + Vector option_group_items; + for (auto const& child : opt_group_element->children_as_vector()) { + if (auto const& option_element = as_if(*child)) { + if (!option_element->has_attribute(Web::HTML::AttributeNames::hidden)) + option_group_items.append(SelectItemOption { id_counter++, option_element->selected(), option_element->disabled(), option_element, strip_newlines(option_element->label()), option_element->value() }); + } } + m_select_items.append(SelectItemOptionGroup { opt_group_element->get_attribute(AttributeNames::label).value_or(String {}), option_group_items }); } - m_select_items.append(SelectItemOptionGroup { opt_group_element.get_attribute(AttributeNames::label).value_or(String {}), option_group_items }); } - if (is(*child)) { - auto& option_element = as(*child); - m_select_items.append(SelectItemOption { id_counter++, option_element.selected(), option_element.disabled(), option_element, strip_newlines(option_element.label()), option_element.value() }); + if (auto const& option_element = as_if(*child)) { + if (!option_element->has_attribute(Web::HTML::AttributeNames::hidden)) + m_select_items.append(SelectItemOption { id_counter++, option_element->selected(), option_element->disabled(), option_element, strip_newlines(option_element->label()), option_element->value() }); } - if (is(*child)) - m_select_items.append(SelectItemSeparator {}); + if (auto const* hr_element = as_if(*child)) { + if (!hr_element->has_attribute(Web::HTML::AttributeNames::hidden)) + m_select_items.append(SelectItemSeparator {}); + } } // Request select dropdown