mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
LibWeb: Implement HTMLOptionElement.label more correctly
This shouldn't just be a simple reflection of the label attribute. It also needs fallback to the HTMLOptionElement.text property if the label attribute is absent.
This commit is contained in:
parent
f7993495bd
commit
4c2d4cdf50
Notes:
github-actions[bot]
2024-11-15 11:55:47 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/4c2d4cdf501 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2355
4 changed files with 25 additions and 5 deletions
|
@ -99,6 +99,23 @@ static void concatenate_descendants_text_content(DOM::Node const* node, StringBu
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-label
|
||||||
|
String HTMLOptionElement::label() const
|
||||||
|
{
|
||||||
|
// The label IDL attribute, on getting, if there is a label content attribute,
|
||||||
|
// must return that attribute's value; otherwise, it must return the element's label.
|
||||||
|
if (auto label = attribute(HTML::AttributeNames::label); label.has_value())
|
||||||
|
return label.release_value();
|
||||||
|
|
||||||
|
return text();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-label
|
||||||
|
void HTMLOptionElement::set_label(String const& label)
|
||||||
|
{
|
||||||
|
MUST(set_attribute(HTML::AttributeNames::label, label));
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
|
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option-text
|
||||||
String HTMLOptionElement::text() const
|
String HTMLOptionElement::text() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,9 @@ public:
|
||||||
String text() const;
|
String text() const;
|
||||||
void set_text(String const&);
|
void set_text(String const&);
|
||||||
|
|
||||||
|
[[nodiscard]] String label() const;
|
||||||
|
void set_label(String const&);
|
||||||
|
|
||||||
int index() const;
|
int index() const;
|
||||||
|
|
||||||
bool disabled() const;
|
bool disabled() const;
|
||||||
|
|
|
@ -7,7 +7,7 @@ interface HTMLOptionElement : HTMLElement {
|
||||||
|
|
||||||
[CEReactions, Reflect] attribute boolean disabled;
|
[CEReactions, Reflect] attribute boolean disabled;
|
||||||
readonly attribute HTMLFormElement? form;
|
readonly attribute HTMLFormElement? form;
|
||||||
[CEReactions, Reflect] attribute DOMString label;
|
[CEReactions] attribute DOMString label;
|
||||||
[CEReactions, Reflect=selected] attribute boolean defaultSelected;
|
[CEReactions, Reflect=selected] attribute boolean defaultSelected;
|
||||||
attribute boolean selected;
|
attribute boolean selected;
|
||||||
[CEReactions] attribute DOMString value;
|
[CEReactions] attribute DOMString value;
|
||||||
|
|
|
@ -6,18 +6,18 @@ Rerun
|
||||||
|
|
||||||
Found 12 tests
|
Found 12 tests
|
||||||
|
|
||||||
7 Pass
|
9 Pass
|
||||||
5 Fail
|
3 Fail
|
||||||
Details
|
Details
|
||||||
Result Test Name MessagePass No children, no label
|
Result Test Name MessagePass No children, no label
|
||||||
Pass No children, empty label
|
Pass No children, empty label
|
||||||
Pass No children, label
|
Pass No children, label
|
||||||
Fail No children, namespaced label
|
Fail No children, namespaced label
|
||||||
Fail Single child, no label
|
Pass Single child, no label
|
||||||
Pass Single child, empty label
|
Pass Single child, empty label
|
||||||
Pass Single child, label
|
Pass Single child, label
|
||||||
Fail Single child, namespaced label
|
Fail Single child, namespaced label
|
||||||
Fail Two children, no label
|
Pass Two children, no label
|
||||||
Pass Two children, empty label
|
Pass Two children, empty label
|
||||||
Pass Two children, label
|
Pass Two children, label
|
||||||
Fail Two children, namespaced label
|
Fail Two children, namespaced label
|
Loading…
Reference in a new issue