Fire event for when popup is toggled.

This commit is contained in:
Peter Kaske 2022-03-29 23:17:49 +02:00
parent 721f2a4f4a
commit 3af695daab
2 changed files with 8 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@tp/tp-popup", "name": "@tp/tp-popup",
"version": "1.0.4", "version": "1.0.5",
"description": "", "description": "",
"main": "tp-popup.js", "main": "tp-popup.js",
"scripts": { "scripts": {

View File

@ -117,6 +117,13 @@ class TpPopup extends EventHelpers(Position(DomQuery(LitElement))) {
this.listen(this, 'click', '_onClick'); 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() { disconnectedCallback() {
super.disconnectedCallback(); super.disconnectedCallback();
this._cleanupEvents(); this._cleanupEvents();