From e49640c56c7edff9b9a6dd3469917994380bc080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20D=C3=B6ll?= Date: Wed, 6 Nov 2024 09:46:29 +0000 Subject: [PATCH] fix: add event listener add the end --- package.json | 2 +- src/index.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f5b08e2..ec0908c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@htmx/htmx-toasts", - "version": "1.0.0", + "version": "1.0.1", "description": "A simple toast notification system for htmx", "repository": "zeiss/htmx-toasts", "type": "module", diff --git a/src/index.ts b/src/index.ts index 7488beb..fb6ef1c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -54,8 +54,6 @@ export class HTMXToastsElement extends HTMLElement { notifications = new Array() connectedCallback(): void { - window.addEventListener('htmx-toasts:notify', ((e: CustomEvent) => this.addToast(e)) as EventListener) - if (!this.hasAttribute('role')) { this.setAttribute('role', 'alert') } @@ -75,6 +73,8 @@ export class HTMXToastsElement extends HTMLElement { styles.href = 'https://unpkg.com/fiber-htmx@1.3.32/dist/out.css' styles.type = 'text/css' this.shadowRoot?.appendChild(styles) + + window.addEventListener('htmx-toasts:notify', ((e: CustomEvent) => this.addToast(e)) as EventListener) } disconnectedCallback(): void {