mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-26 14:28:49 +00:00
LibWeb: Make select element use option's label, not text content
This commit is contained in:
parent
8c4e4ec31b
commit
8f11dfc08a
Notes:
github-actions[bot]
2025-01-04 11:45:06 +00:00
Author: https://github.com/Psychpsyo
Commit: 8f11dfc08a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3130
Reviewed-by: https://github.com/AtkinsSJ ✅
5 changed files with 28 additions and 4 deletions
|
@ -413,7 +413,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
|
|||
for (auto const& child : opt_group_element.children_as_vector()) {
|
||||
if (is<HTMLOptionElement>(*child)) {
|
||||
auto& option_element = verify_cast<HTMLOptionElement>(*child);
|
||||
option_group_items.append(SelectItemOption { id_counter++, option_element.selected(), option_element.disabled(), option_element, strip_newlines(option_element.text_content()), option_element.value() });
|
||||
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 });
|
||||
|
@ -421,7 +421,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
|
|||
|
||||
if (is<HTMLOptionElement>(*child)) {
|
||||
auto& option_element = verify_cast<HTMLOptionElement>(*child);
|
||||
m_select_items.append(SelectItemOption { id_counter++, option_element.selected(), option_element.disabled(), option_element, strip_newlines(option_element.text_content()), option_element.value() });
|
||||
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<HTMLHRElement>(*child))
|
||||
|
@ -567,15 +567,21 @@ void HTMLSelectElement::create_shadow_tree_if_needed()
|
|||
update_inner_text_element();
|
||||
}
|
||||
|
||||
void HTMLSelectElement::update_inner_text_element(Badge<HTMLOptionElement>)
|
||||
{
|
||||
update_inner_text_element();
|
||||
}
|
||||
|
||||
// FIXME: This needs to be called any time the selected option's children are modified.
|
||||
void HTMLSelectElement::update_inner_text_element()
|
||||
{
|
||||
if (!m_inner_text_element)
|
||||
return;
|
||||
|
||||
// Update inner text element to text content of selected option
|
||||
// Update inner text element to the label of the selected option
|
||||
for (auto const& option_element : list_of_options()) {
|
||||
if (option_element->selected()) {
|
||||
m_inner_text_element->set_text_content(strip_newlines(option_element->text_content()));
|
||||
m_inner_text_element->set_text_content(strip_newlines(option_element->label()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue