mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-21 23:20:20 +00:00
LibWeb: Make select element use option's label, not text content
This commit is contained in:
parent
6319dedbcd
commit
dbc7e6bd2f
5 changed files with 22 additions and 3 deletions
|
@ -114,6 +114,13 @@ String HTMLOptionElement::label() const
|
||||||
void HTMLOptionElement::set_label(String const& label)
|
void HTMLOptionElement::set_label(String const& label)
|
||||||
{
|
{
|
||||||
MUST(set_attribute(HTML::AttributeNames::label, label));
|
MUST(set_attribute(HTML::AttributeNames::label, label));
|
||||||
|
|
||||||
|
// NOTE: This option's select element may need to show different contents now.
|
||||||
|
if (selected()) {
|
||||||
|
if (auto select_element = first_ancestor_of_type<HTMLSelectElement>()) {
|
||||||
|
select_element->update_inner_text_element();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
|
||||||
|
|
|
@ -399,7 +399,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
|
||||||
for (auto const& child : opt_group_element.children_as_vector()) {
|
for (auto const& child : opt_group_element.children_as_vector()) {
|
||||||
if (is<HTMLOptionElement>(*child)) {
|
if (is<HTMLOptionElement>(*child)) {
|
||||||
auto& option_element = verify_cast<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 });
|
m_select_items.append(SelectItemOptionGroup { opt_group_element.get_attribute(AttributeNames::label).value_or(String {}), option_group_items });
|
||||||
|
@ -407,7 +407,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
|
||||||
|
|
||||||
if (is<HTMLOptionElement>(*child)) {
|
if (is<HTMLOptionElement>(*child)) {
|
||||||
auto& option_element = verify_cast<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))
|
if (is<HTMLHRElement>(*child))
|
||||||
|
@ -553,6 +553,7 @@ void HTMLSelectElement::create_shadow_tree_if_needed()
|
||||||
update_inner_text_element();
|
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()
|
void HTMLSelectElement::update_inner_text_element()
|
||||||
{
|
{
|
||||||
if (!m_inner_text_element)
|
if (!m_inner_text_element)
|
||||||
|
@ -561,7 +562,7 @@ void HTMLSelectElement::update_inner_text_element()
|
||||||
// Update inner text element to text content of selected option
|
// Update inner text element to text content of selected option
|
||||||
for (auto const& option_element : list_of_options()) {
|
for (auto const& option_element : list_of_options()) {
|
||||||
if (option_element->selected()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,6 +97,8 @@ public:
|
||||||
void update_selectedness();
|
void update_selectedness();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class HTMLOptionElement;
|
||||||
|
|
||||||
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
|
HTMLSelectElement(DOM::Document&, DOM::QualifiedName);
|
||||||
|
|
||||||
virtual void initialize(JS::Realm&) override;
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
|
4
Tests/LibWeb/Ref/expected/select-option-use-label.html
Normal file
4
Tests/LibWeb/Ref/expected/select-option-use-label.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<!doctype html>
|
||||||
|
<select>
|
||||||
|
<option>label</option>
|
||||||
|
</select>
|
5
Tests/LibWeb/Ref/input/select-option-use-label.html
Normal file
5
Tests/LibWeb/Ref/input/select-option-use-label.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<!doctype html>
|
||||||
|
<link rel="match" href="../expected/select-option-use-label.html" />
|
||||||
|
<select>
|
||||||
|
<option label="label"></option>
|
||||||
|
</select>
|
Loading…
Reference in a new issue