diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.cpp b/Libraries/LibWeb/HTML/HTMLInputElement.cpp index 734839a3dff..efe49cbe969 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLInputElement.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -190,6 +191,39 @@ void HTMLInputElement::set_indeterminate(bool value) m_indeterminate = value; } +// https://html.spec.whatwg.org/multipage/input.html#dom-input-list +GC::Ptr HTMLInputElement::list() const +{ + // The list IDL attribute must return the current suggestions source element, if any, or null otherwise. + if (auto data_list_element = suggestions_source_element(); data_list_element.has_value()) + return *data_list_element; + + return nullptr; +} + +// https://html.spec.whatwg.org/multipage/input.html#concept-input-list +Optional> HTMLInputElement::suggestions_source_element() const +{ + // The suggestions source element is the first element in the tree in tree order to have an ID equal to the value of the list attribute, + // if that element is a datalist element. If there is no list attribute, or if there is no element with that ID, + // or if the first element with that ID is not a datalist element, then there is no suggestions source element. + Optional> result; + if (auto list_attribute_value = get_attribute(HTML::AttributeNames::list); list_attribute_value.has_value()) { + root().for_each_in_inclusive_subtree_of_type([&](auto& element) { + if (element.id() == *list_attribute_value) { + if (auto data_list_element = as_if(element)) + result = *data_list_element; + + return TraversalDecision::Break; + } + + return TraversalDecision::Continue; + }); + } + + return result; +} + // https://html.spec.whatwg.org/multipage/input.html#compiled-pattern-regular-expression Optional> HTMLInputElement::compiled_pattern_regular_expression() const { diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.h b/Libraries/LibWeb/HTML/HTMLInputElement.h index 03796ab2027..7bcbc8f32a1 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.h +++ b/Libraries/LibWeb/HTML/HTMLInputElement.h @@ -106,6 +106,8 @@ public: bool indeterminate() const { return m_indeterminate; } void set_indeterminate(bool); + GC::Ptr list() const; + void did_pick_color(Optional picked_color, ColorPickerUpdateState state); enum class MultipleHandling { @@ -356,6 +358,8 @@ private: Optional> compiled_pattern_regular_expression() const; + Optional> suggestions_source_element() const; + Optional m_load_event_delayer; // https://html.spec.whatwg.org/multipage/input.html#dom-input-indeterminate diff --git a/Libraries/LibWeb/HTML/HTMLInputElement.idl b/Libraries/LibWeb/HTML/HTMLInputElement.idl index ebacce7ebec..10339da9ca6 100644 --- a/Libraries/LibWeb/HTML/HTMLInputElement.idl +++ b/Libraries/LibWeb/HTML/HTMLInputElement.idl @@ -1,3 +1,4 @@ +#import #import #import #import @@ -25,7 +26,7 @@ interface HTMLInputElement : HTMLElement { [CEReactions, Reflect=formtarget] attribute DOMString formTarget; [CEReactions] attribute unsigned long height; attribute boolean indeterminate; - [FIXME] readonly attribute HTMLDataListElement? list; + readonly attribute HTMLDataListElement? list; [CEReactions, Reflect] attribute DOMString max; [CEReactions] attribute long maxLength; [CEReactions, Reflect] attribute DOMString min; diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-list.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-list.txt new file mode 100644 index 00000000000..f62523e0506 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/forms/the-input-element/input-list.txt @@ -0,0 +1,11 @@ +Harness status: OK + +Found 6 tests + +6 Pass +Pass getting .list of input must return the datalist with that id +Pass getting .list of input must return null if it has no list attribute +Pass getting .list of input must return null if the list attribute is a non-datalist's id +Pass getting .list of input must return null if the list attribute is no element's id +Pass getting .list of input must return null if the list attribute is used in a non-datalist earlier than a datalist +Pass getting .list of input must return the datalist with that id even if a later non-datalist also has the id \ No newline at end of file diff --git a/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/input-element-list.txt b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/input-element-list.txt new file mode 100644 index 00000000000..6cff615ad21 --- /dev/null +++ b/Tests/LibWeb/Text/expected/wpt-import/shadow-dom/input-element-list.txt @@ -0,0 +1,7 @@ +Harness status: OK + +Found 2 tests + +2 Pass +Pass Input element's list attribute should point to the datalist element. +Pass Input element's list attribute should point to the datalist element in Shadow DOM. \ No newline at end of file diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/input-list.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/input-list.html new file mode 100644 index 00000000000..0d4c11a70bb --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/forms/the-input-element/input-list.html @@ -0,0 +1,67 @@ + + + + input list attribute + + + + +

+

input_list

+

+ +
+ +
+ +
+ + + + + +

+ + + + + + + + + +

+ +

+

+

+

+

+

+
+ + + + diff --git a/Tests/LibWeb/Text/input/wpt-import/shadow-dom/input-element-list.html b/Tests/LibWeb/Text/input/wpt-import/shadow-dom/input-element-list.html new file mode 100644 index 00000000000..a5002194092 --- /dev/null +++ b/Tests/LibWeb/Text/input/wpt-import/shadow-dom/input-element-list.html @@ -0,0 +1,39 @@ + + +Input.list + + +
+ +
+