diff --git a/Tests/LibWeb/Text/expected/select.txt b/Tests/LibWeb/Text/expected/select.txt index 26f280fa42e..f10468bcba1 100644 --- a/Tests/LibWeb/Text/expected/select.txt +++ b/Tests/LibWeb/Text/expected/select.txt @@ -4,3 +4,6 @@ 4. 3 5. "three" 6. "Three" +7. 45 +8. 0 +9. 0 diff --git a/Tests/LibWeb/Text/input/select.html b/Tests/LibWeb/Text/input/select.html index 574e5c71a6d..f27c66298b3 100644 --- a/Tests/LibWeb/Text/input/select.html +++ b/Tests/LibWeb/Text/input/select.html @@ -74,5 +74,26 @@ `; return select.value; }); + + // 7. Set select size property + testPart(() => { + const select = document.createElement('select'); + select.size = '45'; + return select.size; + }); + + // 8. Set select size property invalid + testPart(() => { + const select = document.createElement('select'); + select.size = '12'; + select.size = 'fadsfsd'; + return select.size; + }); + + // 9. Get select size default + testPart(() => { + const select = document.createElement('select'); + return select.size; + }); }); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 0f26de16f24..094a4e10ffe 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -67,6 +68,22 @@ void HTMLSelectElement::adjust_computed_style(CSS::StyleProperties& style) style.set_property(CSS::PropertyID::Display, CSS::DisplayStyleValue::create(CSS::Display::from_short(CSS::Display::Short::InlineBlock))); } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-size +WebIDL::UnsignedLong HTMLSelectElement::size() const +{ + // The size IDL attribute must reflect the respective content attributes of the same name. The size IDL attribute has a default value of 0. + if (auto size_string = get_attribute(HTML::AttributeNames::size); size_string.has_value()) { + if (auto size = parse_non_negative_integer(*size_string); size.has_value()) + return *size; + } + return 0; +} + +WebIDL::ExceptionOr HTMLSelectElement::set_size(WebIDL::UnsignedLong size) +{ + return set_attribute(HTML::AttributeNames::size, MUST(String::number(size))); +} + // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options JS::GCPtr const& HTMLSelectElement::options() { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index a0387c79207..069f5fe6450 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -13,6 +13,7 @@ #include #include #include +#include namespace Web::HTML { @@ -28,6 +29,9 @@ public: virtual void adjust_computed_style(CSS::StyleProperties&) override; + WebIDL::UnsignedLong size() const; + WebIDL::ExceptionOr set_size(WebIDL::UnsignedLong); + JS::GCPtr const& options(); size_t length(); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl index e7b9c7c00da..893a90a1013 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl @@ -13,7 +13,7 @@ interface HTMLSelectElement : HTMLElement { [CEReactions, Reflect] attribute boolean multiple; [CEReactions, Reflect] attribute DOMString name; [CEReactions, Reflect] attribute boolean required; - // FIXME: [CEReactions] attribute unsigned long size; + [CEReactions] attribute unsigned long size; readonly attribute DOMString type;