diff --git a/src/panels/config/labels/dialog-label-detail.ts b/src/panels/config/labels/dialog-label-detail.ts index 916d99f45da7..2e59596663fd 100644 --- a/src/panels/config/labels/dialog-label-detail.ts +++ b/src/panels/config/labels/dialog-label-detail.ts @@ -5,9 +5,10 @@ import { fireEvent } from "../../../common/dom/fire_event"; import "../../../components/ha-alert"; import "../../../components/ha-button"; import "../../../components/ha-color-picker"; -import { createCloseHeading } from "../../../components/ha-dialog"; +import "../../../components/ha-dialog-footer"; import "../../../components/ha-icon-picker"; import "../../../components/ha-switch"; +import "../../../components/ha-wa-dialog"; import "../../../components/ha-textarea"; import "../../../components/ha-textfield"; import type { LabelRegistryEntryMutableParams } from "../../../data/label_registry"; @@ -37,6 +38,8 @@ class DialogLabelDetail @state() private _submitting = false; + @state() private _open = false; + public showDialog(params: LabelDetailDialogParams): void { this._params = params; this._error = undefined; @@ -51,20 +54,17 @@ class DialogLabelDetail this._color = ""; this._description = ""; } - document.body.addEventListener("keydown", this._handleKeyPress); + this._open = true; } - private _handleKeyPress = (ev: KeyboardEvent) => { - if (ev.key === "Escape") { - ev.stopPropagation(); - } - }; - public closeDialog() { + this._open = false; + return true; + } + + private _dialogClosed(): void { this._params = undefined; fireEvent(this, "dialog-closed", { dialog: this.localName }); - document.body.removeEventListener("keydown", this._handleKeyPress); - return true; } protected render() { @@ -73,17 +73,13 @@ class DialogLabelDetail } return html` - ${this._error @@ -91,7 +87,7 @@ class DialogLabelDetail : ""} - ${this._params.entry && this._params.removeEntry - ? html` - - ${this.hass!.localize("ui.panel.config.labels.detail.delete")} - - ` - : nothing} - - ${this._params.entry - ? this.hass!.localize("ui.panel.config.labels.detail.update") - : this.hass!.localize("ui.panel.config.labels.detail.create")} - - + + + ${this._params.entry && this._params.removeEntry + ? html` + + ${this.hass!.localize("ui.panel.config.labels.detail.delete")} + + ` + : nothing} + + ${this._params.entry + ? this.hass!.localize("ui.panel.config.labels.detail.update") + : this.hass!.localize("ui.panel.config.labels.detail.create")} + + + `; }