diff --git a/src/components.d.ts b/src/components.d.ts index 620dbd929..bea93282b 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -358,7 +358,7 @@ export namespace Components { /** * Hides the dropdown panel */ - "hide": () => Promise; + "hide": () => Promise; /** * Indicates whether or not the dropdown is open. You can use this in lieu of the show/hide methods. */ @@ -381,7 +381,7 @@ export namespace Components { /** * Shows the dropdown panel */ - "show": () => Promise; + "show": () => Promise; /** * The distance in pixels from which to offset the panel along its trigger. */ diff --git a/src/components/alert/alert.tsx b/src/components/alert/alert.tsx index ac77b6715..78fa7c46c 100644 --- a/src/components/alert/alert.tsx +++ b/src/components/alert/alert.tsx @@ -64,8 +64,9 @@ export class Tab { /** Shows the alert. */ @Method() async show() { - const slShow = this.slShow.emit(); + if (this.open) return; + const slShow = this.slShow.emit(); if (slShow.defaultPrevented) { return false; } @@ -78,8 +79,9 @@ export class Tab { /** Hides the alert */ @Method() async hide() { - const slHide = this.slHide.emit(); + if (!this.open) return; + const slHide = this.slHide.emit(); if (slHide.defaultPrevented) { return false; } diff --git a/src/components/details/details.tsx b/src/components/details/details.tsx index cf8d97aa6..204a0d811 100644 --- a/src/components/details/details.tsx +++ b/src/components/details/details.tsx @@ -76,8 +76,9 @@ export class Details { /** Shows the alert. */ @Method() async show() { - const slShow = this.slShow.emit(); + if (this.open) return; + const slShow = this.slShow.emit(); if (slShow.defaultPrevented) { return false; } @@ -98,8 +99,9 @@ export class Details { /** Hides the alert */ @Method() async hide() { - const slHide = this.slHide.emit(); + if (!this.open) return; + const slHide = this.slHide.emit(); if (slHide.defaultPrevented) { return false; } diff --git a/src/components/dialog/dialog.tsx b/src/components/dialog/dialog.tsx index c5e0666fd..007a9b415 100644 --- a/src/components/dialog/dialog.tsx +++ b/src/components/dialog/dialog.tsx @@ -99,8 +99,9 @@ export class Dialog { /** Shows the dialog */ @Method() async show() { - const slShow = this.slShow.emit(); + if (this.open) return; + const slShow = this.slShow.emit(); if (slShow.defaultPrevented) { return false; } @@ -116,8 +117,9 @@ export class Dialog { /** Hides the dialog */ @Method() async hide() { - const slHide = this.slHide.emit(); + if (!this.open) return; + const slHide = this.slHide.emit(); if (slHide.defaultPrevented) { return false; } diff --git a/src/components/drawer/drawer.tsx b/src/components/drawer/drawer.tsx index b37b13abc..7066956a8 100644 --- a/src/components/drawer/drawer.tsx +++ b/src/components/drawer/drawer.tsx @@ -107,8 +107,9 @@ export class Drawer { /** Shows the drawer */ @Method() async show() { - const slShow = this.slShow.emit(); + if (this.open) return; + const slShow = this.slShow.emit(); if (slShow.defaultPrevented) { return false; } @@ -128,8 +129,9 @@ export class Drawer { /** Hides the drawer */ @Method() async hide() { - const slHide = this.slHide.emit(); + if (!this.open) return; + const slHide = this.slHide.emit(); if (slHide.defaultPrevented) { return false; } diff --git a/src/components/dropdown/dropdown.tsx b/src/components/dropdown/dropdown.tsx index 4920cce16..9a6d0cb36 100644 --- a/src/components/dropdown/dropdown.tsx +++ b/src/components/dropdown/dropdown.tsx @@ -23,9 +23,6 @@ let id = 0; }) export class Dropdown { componentId = `dropdown-${++id}`; - ignoreMouseEvents = false; - ignoreMouseTimeout: any; - ignoreOpenWatcher = false; panel: HTMLElement; popover: Popover; trigger: HTMLElement; @@ -79,9 +76,7 @@ export class Dropdown { @Watch('open') handleOpenChange() { - if (!this.ignoreOpenWatcher) { - this.open ? this.show() : this.hide(); - } + this.open ? this.show() : this.hide(); } @Watch('placement') @@ -128,47 +123,39 @@ export class Dropdown { /** Shows the dropdown panel */ @Method() async show() { - this.ignoreOpenWatcher = true; - this.open = true; + if (this.open) return; const slShow = this.slShow.emit(); - if (slShow.defaultPrevented) { - this.open = false; - this.ignoreOpenWatcher = false; - return; + return false; } - this.popover.show(); - this.ignoreOpenWatcher = false; - this.panel.addEventListener('slActivate', this.handleMenuItemActivate); this.panel.addEventListener('slSelect', this.handlePanelSelect); document.addEventListener('mousedown', this.handleDocumentMouseDown); document.addEventListener('keydown', this.handleDocumentKeyDown); + + this.popover.show(); + this.open = true; } /** Hides the dropdown panel */ @Method() async hide() { - this.ignoreOpenWatcher = true; - this.open = false; + if (!this.open) return; const slHide = this.slHide.emit(); - if (slHide.defaultPrevented) { - this.open = true; - this.ignoreOpenWatcher = false; - return; + return false; } - this.popover.hide(); - this.ignoreOpenWatcher = false; - this.panel.removeEventListener('slActivate', this.handleMenuItemActivate); this.panel.removeEventListener('slSelect', this.handlePanelSelect); document.removeEventListener('mousedown', this.handleDocumentMouseDown); document.removeEventListener('keydown', this.handleDocumentKeyDown); + + this.popover.hide(); + this.open = false; } focusOnTrigger() { diff --git a/src/components/tooltip/tooltip.tsx b/src/components/tooltip/tooltip.tsx index 22bdd1a5d..7fb112477 100644 --- a/src/components/tooltip/tooltip.tsx +++ b/src/components/tooltip/tooltip.tsx @@ -126,8 +126,9 @@ export class Tooltip { /** Shows the tooltip. */ @Method() async show() { - const slShow = this.slShow.emit(); + if (this.open) return; + const slShow = this.slShow.emit(); if (slShow.defaultPrevented) { return false; } @@ -139,8 +140,9 @@ export class Tooltip { /** Shows the tooltip. */ @Method() async hide() { - const slHide = this.slHide.emit(); + if (!this.open) return; + const slHide = this.slHide.emit(); if (slHide.defaultPrevented) { return false; }