From 27eb70cbba9269ada769a0ea94dd2fe688504c3f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 21 Mar 2022 20:03:37 -0400 Subject: [PATCH] LibWeb: Implement HTMLSelectElement.add() HTMLSelectElement simply defers to its HTMLOptionsCollection. --- Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp | 7 +++++++ Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h | 2 ++ Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl | 2 ++ 3 files changed, 11 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 9853f60e90..838987857e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -34,6 +34,13 @@ RefPtr const& HTMLSelectElement::options() return m_options; } +// https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-add +DOM::ExceptionOr HTMLSelectElement::add(HTMLOptionOrOptGroupElement element, Optional before) +{ + // Similarly, the add(element, before) method must act like its namesake method on that same options collection. + return const_cast&>(options())->add(move(element), move(before)); +} + // https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list NonnullRefPtrVector HTMLSelectElement::list_of_options() const { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index 1d0f3964dc..c8ad0930a6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -23,6 +23,8 @@ public: RefPtr const& options(); + DOM::ExceptionOr add(HTMLOptionOrOptGroupElement element, Optional before = {}); + int selected_index() const; void set_selected_index(int); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl index e473f31070..3717993572 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.idl @@ -8,6 +8,8 @@ interface HTMLSelectElement : HTMLElement { [Reflect] attribute boolean required; [SameObject] readonly attribute HTMLOptionsCollection options; + [CEReactions] undefined add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null); + attribute long selectedIndex; };