From b2d08dcf4c2a5fd88d459eea54a6dcb13ccec521 Mon Sep 17 00:00:00 2001 From: Mustafa UZUN Date: Sat, 23 Dec 2023 21:18:17 +0300 Subject: [PATCH] fix: EventDispatcher allow events without payload --- src/components/drawer/bl-drawer.ts | 6 ++---- src/components/popover/bl-popover.ts | 4 ++-- src/components/tooltip/bl-tooltip.test.ts | 4 ++-- src/components/tooltip/bl-tooltip.ts | 6 +++--- src/utilities/event.ts | 4 ++-- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/drawer/bl-drawer.ts b/src/components/drawer/bl-drawer.ts index 67e80900..47c403c9 100644 --- a/src/components/drawer/bl-drawer.ts +++ b/src/components/drawer/bl-drawer.ts @@ -74,16 +74,14 @@ export default class BlDrawer extends LitElement { } this.domExistence = true; - // FIXME: Allow events without payload - this.onOpen(""); + this.onOpen(); } else { // Give some time for exit animation this.domExistenceSchedule = window.setTimeout(() => { this.domExistence = false; }, 1000); - // FIXME: Allow events without payload - this.onClose(""); + this.onClose(); } } diff --git a/src/components/popover/bl-popover.ts b/src/components/popover/bl-popover.ts index 5e1465f9..16533067 100644 --- a/src/components/popover/bl-popover.ts +++ b/src/components/popover/bl-popover.ts @@ -193,7 +193,7 @@ export default class BlPopover extends LitElement { show() { this._visible = true; this.setPopover(); - this.onBlPopoverShow(""); + this.onBlPopoverShow(); document.addEventListener("click", this._handleClickOutside); document.addEventListener("keydown", this._handleKeydownEvent); document.addEventListener("bl-popover-show", this._handlePopoverShowEvent); @@ -207,7 +207,7 @@ export default class BlPopover extends LitElement { document.removeEventListener("click", this._handleClickOutside); document.removeEventListener("keydown", this._handleKeydownEvent); document.removeEventListener("bl-popover-show", this._handlePopoverShowEvent); - this.onBlPopoverHide(""); + this.onBlPopoverHide(); } /** diff --git a/src/components/tooltip/bl-tooltip.test.ts b/src/components/tooltip/bl-tooltip.test.ts index 92b62f0f..d40d3667 100644 --- a/src/components/tooltip/bl-tooltip.test.ts +++ b/src/components/tooltip/bl-tooltip.test.ts @@ -144,7 +144,7 @@ describe("bl-tooltip", () => { const ev = await oneEvent(el, "bl-tooltip-show"); expect(ev).to.exist; - expect(ev.detail).to.be.equal(""); + expect(ev.detail).to.be.null; }); it("should fires bl-tooltip-hide on mouse leave", async () => { @@ -169,7 +169,7 @@ describe("bl-tooltip", () => { const ev = await oneEvent(el, "bl-tooltip-hide"); expect(ev).to.exist; - expect(ev.detail).to.be.equal(""); + expect(ev.detail).to.be.null; }); it("should show/hide with focus and blur events", async () => { diff --git a/src/components/tooltip/bl-tooltip.ts b/src/components/tooltip/bl-tooltip.ts index d4f88401..5115b24b 100644 --- a/src/components/tooltip/bl-tooltip.ts +++ b/src/components/tooltip/bl-tooltip.ts @@ -46,7 +46,7 @@ export default class BlTooltip extends LitElement { show() { this.popover.target = this.trigger; this.popover.show(); - this.onShow(""); + this.onShow(); } /** @@ -54,7 +54,7 @@ export default class BlTooltip extends LitElement { */ hide() { this.popover.hide(); - this.onHide(""); + this.onHide(); } /** @@ -83,7 +83,7 @@ export default class BlTooltip extends LitElement { diff --git a/src/utilities/event.ts b/src/utilities/event.ts index 52723b3b..12958227 100644 --- a/src/utilities/event.ts +++ b/src/utilities/event.ts @@ -5,11 +5,11 @@ export interface EventOptions { } export interface EventDispatcher { - (value: T, options?: EventOptions): CustomEvent; + (value?: T, options?: EventOptions): CustomEvent; } function dispatcher(target: HTMLElement, eventName: string): EventDispatcher { - return function (value: T, options?: EventOptions) { + return function (value?: T, options?: EventOptions) { const customEvent = new CustomEvent(eventName, { detail: value, bubbles: true,