1
0
mirror of https://github.com/home-assistant/frontend.git synced 2026-04-02 00:27:49 +01:00

Improve dialog open logic (#51328)

This commit is contained in:
Wendelin
2026-04-01 10:40:40 +02:00
committed by GitHub
parent 1da349a36d
commit b55e1c9988
2 changed files with 7 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ export const DialogMixin = <
superClass: T
) =>
class extends superClass implements HassDialogNext<P> {
public dialogNext = true as const;
declare public params?: P;
private _closePromise?: Promise<boolean>;

View File

@@ -26,6 +26,7 @@ export interface HassDialog<T = unknown> extends HTMLElement {
}
export interface HassDialogNext<T = unknown> extends HTMLElement {
dialogNext: true;
params?: T;
closeDialog?: (historyState?: any) => Promise<boolean> | boolean;
}
@@ -168,10 +169,12 @@ export const showDialog = async (
dialogElement = await LOADED[dialogTag].element;
}
if ("showDialog" in dialogElement!) {
if ("dialogNext" in dialogElement! && dialogElement.dialogNext) {
dialogElement!.params = dialogParams;
} else if ("showDialog" in dialogElement!) {
dialogElement.showDialog(dialogParams);
} else {
dialogElement!.params = dialogParams;
throw new Error("Unknown dialog type loaded");
}
(parentElement || element).shadowRoot!.appendChild(dialogElement!);