From c4ee43c5b41770ef69402269c6efa92ad5ded2be Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Sat, 5 Nov 2022 04:51:42 +0000 Subject: [PATCH] LibWeb: Implement HTMLSelectElement.type --- .../Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 13 +++++++++++++ Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h | 2 ++ .../Libraries/LibWeb/HTML/HTMLSelectElement.idl | 2 ++ 3 files changed, 17 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 73dc93c6f3..f5e8845e54 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -129,4 +129,17 @@ i32 HTMLSelectElement::default_tab_index_value() const return 0; } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-type +String const& HTMLSelectElement::type() const +{ + // The type IDL attribute, on getting, must return the string "select-one" if the multiple attribute is absent, and the string "select-multiple" if the multiple attribute is present. + static String select_one = "select-one"sv; + static String select_multiple = "select-multiple"sv; + + if (!has_attribute(AttributeNames::multiple)) + return select_one; + + return select_multiple; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index cde0d812e7..0d50f14510 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -56,6 +56,8 @@ public: // https://html.spec.whatwg.org/multipage/forms.html#category-label virtual bool is_labelable() const override { return true; } + String const& type() const; + private: HTMLSelectElement(DOM::Document&, DOM::QualifiedName); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl index c1a1297d64..b7801b6811 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl @@ -10,6 +10,8 @@ interface HTMLSelectElement : HTMLElement { [Reflect] attribute boolean required; [SameObject] readonly attribute HTMLOptionsCollection options; + readonly attribute DOMString type; + readonly attribute unsigned long length; getter Element? item(unsigned long index); getter Element? namedItem(DOMString name);