From de53eb825a9ba87f4bf8cd51557c0731b6d7b6cf Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 26 Mar 2022 18:05:48 +0000 Subject: [PATCH] LibWeb: Make HTML{Button,Select,TextArea}Element focusable From the HTML spec: Modulo platform conventions, it is suggested that the following elements should be considered as focusable areas and be sequentially focusable: ... - button elements - select elements - textarea elements ... Also add a spec link to the existing HTMLAnchorElement::is_focusable(). Note that this still doesn't allow triggering keyboard-focused buttons, checkboxes, or radio buttons - we don't seem to run the expected activation behavior for any of them. --- Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h | 2 ++ Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h | 4 ++++ Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h | 4 ++++ Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h | 4 ++++ 4 files changed, 14 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h index b55236dd83..a936e7c027 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLAnchorElement.h @@ -23,6 +23,8 @@ public: String target() const { return attribute(HTML::AttributeNames::target); } String download() const { return attribute(HTML::AttributeNames::download); } + // ^EventTarget + // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-a-element virtual bool is_focusable() const override { return has_attribute(HTML::AttributeNames::href); } virtual bool is_html_anchor_element() const override { return true; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h index eba1aacda8..3c08419856 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLButtonElement.h @@ -37,6 +37,10 @@ public: TypeAttributeState type_state() const; void set_type(String const&); + // ^EventTarget + // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-button-element + virtual bool is_focusable() const override { return true; } + // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed virtual bool is_listed() const override { return true; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index 4408531b1d..cbb19ec9ba 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -34,6 +34,10 @@ public: NonnullRefPtrVector list_of_options() const; + // ^EventTarget + // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-select-element + virtual bool is_focusable() const override { return true; } + // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed virtual bool is_listed() const override { return true; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h index 4ea7124dab..23c3148b7e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTextAreaElement.h @@ -29,6 +29,10 @@ public: return textarea; } + // ^EventTarget + // https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute:the-textarea-element + virtual bool is_focusable() const override { return true; } + // ^FormAssociatedElement // https://html.spec.whatwg.org/multipage/forms.html#category-listed virtual bool is_listed() const override { return true; }