You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by hn...@apache.org on 2020/03/02 08:23:27 UTC

[myfaces-tobago] 06/06: tobago-dropdown: add support for 'tab' key

This is an automated email from the ASF dual-hosted git repository.

hnoeth pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/myfaces-tobago.git

commit 9f1918c8e5f3dd4aff173be02289c1c585a96f27
Author: Henning Noeth <hn...@apache.org>
AuthorDate: Thu Feb 27 17:14:23 2020 +0100

    tobago-dropdown: add support for 'tab' key
    
    issue: TOBAGO-1633: TS refactoring
---
 .../src/main/npm/ts/tobago-dropdown.ts             | 26 +++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts
index 908a24f..e0da2ab 100644
--- a/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts
+++ b/tobago-theme/tobago-theme-standard/src/main/npm/ts/tobago-dropdown.ts
@@ -81,7 +81,8 @@ class Dropdown extends HTMLElement {
       }, 0);
     } else if (this.dropdownVisible()
         && (event.code === "ArrowUp" || event.code === "ArrowDown"
-            || event.code === "ArrowLeft" || event.code === "ArrowRight")) {
+            || event.code === "ArrowLeft" || event.code === "ArrowRight"
+            || event.code === "Tab")) {
       event.preventDefault();
       event.stopPropagation();
 
@@ -95,6 +96,29 @@ class Dropdown extends HTMLElement {
         this.activeDropdownEntry.children[0].focus();
       } else if (event.code === "ArrowLeft" && this.activeDropdownEntry.parent) {
         this.activeDropdownEntry.parent.focus();
+      } else if (!event.shiftKey && event.code === "Tab") {
+        if (this.activeDropdownEntry.children.length > 0) {
+          this.activeDropdownEntry.children[0].focus();
+        } else if (this.activeDropdownEntry.next) {
+          this.activeDropdownEntry.next.focus();
+        } else {
+          let parent: DropdownEntry = this.activeDropdownEntry.parent;
+          while (parent) {
+            if (parent.next) {
+              this.activeDropdownEntry.clear();
+              parent.next.focus();
+              break;
+            } else {
+              parent = parent.parent;
+            }
+          }
+        }
+      } else if (event.shiftKey && event.code === "Tab") {
+        if (this.activeDropdownEntry.previous) {
+          this.activeDropdownEntry.previous.focus();
+        } else if (this.activeDropdownEntry.parent) {
+          this.activeDropdownEntry.parent.focus();
+        }
       }
     } else if (this.dropdownVisible() && event.code === "Escape") {
       event.preventDefault();