Finally fix popup closing?

This commit is contained in:
Thomas Lovén 2022-07-26 21:54:49 +00:00
parent 18eec919a0
commit df745e7f3b

View File

@ -3,8 +3,6 @@ import { property, query } from "lit/decorators.js";
import { unsafeHTML } from "lit/directives/unsafe-html.js"; import { unsafeHTML } from "lit/directives/unsafe-html.js";
import { provideHass, loadLoadCardHelpers, hass_base_el } from "../helpers"; import { provideHass, loadLoadCardHelpers, hass_base_el } from "../helpers";
let aaa = 0;
class BrowserModPopup extends LitElement { class BrowserModPopup extends LitElement {
@property() open; @property() open;
@property() content; @property() content;
@ -52,10 +50,11 @@ class BrowserModPopup extends LitElement {
} }
this._autocloseListener = undefined; this._autocloseListener = undefined;
if (this._autoclose) { if (this._autoclose) {
this._autocloseListener = this._dismiss.bind(this); this._autocloseListener = () => this.dialog.close();
window.browser_mod.addEventListener( window.browser_mod.addEventListener(
"browser-mod-activity", "browser-mod-activity",
this._autocloseListener this._autocloseListener,
{ once: true }
); );
} }
} }
@ -78,7 +77,10 @@ class BrowserModPopup extends LitElement {
} = {} } = {}
) { ) {
this.title = title; this.title = title;
if (content && typeof content === "object") { if (content && content instanceof HTMLElement) {
this.card = undefined;
this.content = content;
} else if (content && typeof content === "object") {
// Create a card from config in content // Create a card from config in content
this.card = true; this.card = true;
const helpers = await window.loadCardHelpers(); const helpers = await window.loadCardHelpers();
@ -112,21 +114,21 @@ class BrowserModPopup extends LitElement {
async _primary() { async _primary() {
if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined; if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined;
await this.closeDialog(); this.dialog.close();
this._actions?.right_button_action?.(); this._actions?.right_button_action?.();
} }
async _secondary() { async _secondary() {
if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined; if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined;
await this.closeDialog(); this.dialog.close();
this._actions?.left_button_action?.(); this._actions?.left_button_action?.();
} }
async _dismiss() { async _dismiss(ev?) {
await this.closeDialog(); this.dialog.close();
this._actions?.dismiss_action?.(); this._actions?.dismiss_action?.();
} }
async _timeout() { async _timeout() {
if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined; if (this._actions?.dismiss_action) this._actions.dismiss_action = undefined;
await this.closeDialog(); this.dialog.close();
this._actions?.timeout_action?.(); this._actions?.timeout_action?.();
} }
@ -136,10 +138,12 @@ class BrowserModPopup extends LitElement {
return html` return html`
<ha-dialog <ha-dialog
open open
@closed=${this.closeDialog}
@closing=${this._dismiss}
.heading=${this.title !== undefined} .heading=${this.title !== undefined}
?hideActions=${this.actions === undefined} ?hideActions=${this.actions === undefined}
.scrimClickAction=${this.dismissable ? this._dismiss : ""} .scrimClickAction=${this.dismissable ? "close" : ""}
.escapeKeyAction=${this.dismissable ? this._dismiss : ""} .escapeKeyAction=${this.dismissable ? "close" : ""}
> >
${this.timeout ${this.timeout
? html` <div slot="heading" class="progress"></div> ` ? html` <div slot="heading" class="progress"></div> `