From 3af695daab3f8d677a3a3ec3b5eafdce1aa21181 Mon Sep 17 00:00:00 2001 From: Peter Kaske Date: Tue, 29 Mar 2022 23:17:49 +0200 Subject: [PATCH] Fire event for when popup is toggled. --- package.json | 2 +- tp-popup.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7ee495b..343cf3c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tp/tp-popup", - "version": "1.0.4", + "version": "1.0.5", "description": "", "main": "tp-popup.js", "scripts": { diff --git a/tp-popup.js b/tp-popup.js index 3ed55fa..9deffc5 100644 --- a/tp-popup.js +++ b/tp-popup.js @@ -117,6 +117,13 @@ class TpPopup extends EventHelpers(Position(DomQuery(LitElement))) { this.listen(this, 'click', '_onClick'); } + updated(changes) { + // Fire event only if isOpen wasn't undefined before. Otherwise an event is fired at the first render. + if (changes.has('isOpen') && changes.get('isOpen') !== undefined) { + this.dispatchEvent(new CustomEvent('is-open-changed', { detail: this.isOpen, bubbles: true, composed: true })); + } + } + disconnectedCallback() { super.disconnectedCallback(); this._cleanupEvents();