From 4a128c904ecb6a6ce3466d8ed4c9b9b5cf5d09f8 Mon Sep 17 00:00:00 2001 From: Aidan Timson Date: Thu, 12 Feb 2026 12:33:12 +0000 Subject: [PATCH] Migrate enter code dialog to wa (#29592) * Move enter code dialog migration to dedicated branch * Fix * Make small * Small --- src/dialogs/enter-code/dialog-enter-code.ts | 85 +++++++++++++-------- 1 file changed, 52 insertions(+), 33 deletions(-) diff --git a/src/dialogs/enter-code/dialog-enter-code.ts b/src/dialogs/enter-code/dialog-enter-code.ts index 65e78d001a..1f9cbbad42 100644 --- a/src/dialogs/enter-code/dialog-enter-code.ts +++ b/src/dialogs/enter-code/dialog-enter-code.ts @@ -5,8 +5,9 @@ import { ifDefined } from "lit/directives/if-defined"; import { fireEvent } from "../../common/dom/fire_event"; import "../../components/ha-button"; import "../../components/ha-control-button"; -import { createCloseHeading } from "../../components/ha-dialog"; +import "../../components/ha-dialog-footer"; import "../../components/ha-textfield"; +import "../../components/ha-wa-dialog"; import type { HaTextField } from "../../components/ha-textfield"; import type { HomeAssistant } from "../../types"; import type { HassDialog } from "../make-dialog-manager"; @@ -36,34 +37,51 @@ export class DialogEnterCode @state() private _dialogParams?: EnterCodeDialogParams; + @state() private _open = false; + @query("#code") private _input?: HaTextField; @state() private _showClearButton = false; @state() private _narrow = false; + private _closeAction?: "submit" | "cancel"; + public async showDialog(dialogParams: EnterCodeDialogParams): Promise { this._dialogParams = dialogParams; + this._open = true; + this._showClearButton = false; + this._closeAction = undefined; this._narrow = matchMedia( "all and (max-width: 450px), all and (max-height: 500px)" ).matches; await this.updateComplete; } - public closeDialog() { + public closeDialog(): boolean { + this._open = false; + return true; + } + + private _dialogClosed(): void { + if (!this._closeAction) { + this._dialogParams?.cancel?.(); + } this._dialogParams = undefined; this._showClearButton = false; + this._closeAction = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); - return true; } private _submit(): void { this._dialogParams?.submit?.(this._input?.value ?? ""); + this._closeAction = "submit"; this.closeDialog(); } private _cancel(): void { this._dialogParams?.cancel?.(); + this._closeAction = "cancel"; this.closeDialog(); } @@ -93,15 +111,17 @@ export class DialogEnterCode if (isText) { return html` - - - ${this._dialogParams.cancelText ?? - this.hass.localize("ui.common.cancel")} - - - ${this._dialogParams.submitText ?? - this.hass.localize("ui.common.submit")} - - + + + ${this._dialogParams.cancelText ?? + this.hass.localize("ui.common.cancel")} + + + ${this._dialogParams.submitText ?? + this.hass.localize("ui.common.submit")} + + + `; } return html` -
${BUTTONS.map((value) => @@ -183,18 +203,17 @@ export class DialogEnterCode )}
-
+ `; } static styles = css` - ha-dialog { + ha-wa-dialog { /* Place above other dialogs */ --dialog-z-index: 104; } ha-textfield { width: 100%; - max-width: 300px; margin: auto; } .container {