myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hno...@apache.org
Subject [myfaces-tobago] 03/06: tobago-dropdown: custom elements, remove jQuery
Date Mon, 02 Mar 2020 08:23:24 GMT
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 7e88b3ef21508a0b4de6791766810ea04fc8864d
Author: Henning Noeth <hnoeth@apache.org>
AuthorDate: Wed Feb 26 17:02:36 2020 +0100

    tobago-dropdown: custom elements, remove jQuery
    
    * improve toggleButtonSelected
    * fix: mouse click
    
    issue: TOBAGO-1633: TS refactoring
---
 .../src/main/npm/ts/tobago-dropdown.ts                     | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

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 9e4f1be..55960a5 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
@@ -57,7 +57,8 @@ class Dropdown extends HTMLElement {
   }
 
   mouseupOnDocument(event: MouseEvent): void {
-    if (!this.toggleButtonSelected() && this.dropdownVisible()) {
+    if (!this.toggleButtonSelected(event) && this.dropdownVisible()
+        && !this.dropdownMenu.contains(event.target as HTMLElement)) {
       this.closeDropdown();
     }
   }
@@ -67,7 +68,7 @@ class Dropdown extends HTMLElement {
       event.preventDefault();
       event.stopPropagation();
       this.closeDropdown();
-    } else if ((this.toggleButtonSelected() || this.dropdownVisible())
+    } else if ((this.toggleButtonSelected(event) || this.dropdownVisible())
         && (event.code === "ArrowUp" || event.code === "ArrowDown"
             || event.code === "ArrowLeft" || event.code === "ArrowRight")) {
       // prevent scrolling with arrow keys
@@ -77,9 +78,7 @@ class Dropdown extends HTMLElement {
   }
 
   keyupOnDocument(event: KeyboardEvent): void {
-    const root = this.getRootNode() as ShadowRoot | Document;
-
-    if (this.toggleButtonSelected() && !this.dropdownVisible()
+    if (this.toggleButtonSelected(event) && !this.dropdownVisible()
         && (event.code === "ArrowUp" || event.code === "ArrowDown")) {
       event.preventDefault();
       event.stopPropagation();
@@ -142,9 +141,8 @@ class Dropdown extends HTMLElement {
     return this.querySelector(":scope > button[data-toggle='dropdown']");
   }
 
-  private toggleButtonSelected(): boolean {
-    const root = this.getRootNode() as ShadowRoot | Document;
-    return root.activeElement === this.toggleButton;
+  private toggleButtonSelected(event: Event): boolean {
+    return this.toggleButton.contains(event.target as HTMLElement);
   }
 
   private inStickyHeader(): boolean {


Mime
View raw message