diff --git a/src/components/ha-menu-item.ts b/src/components/ha-menu-item.ts index dd643f227764..2f2914859640 100644 --- a/src/components/ha-menu-item.ts +++ b/src/components/ha-menu-item.ts @@ -1,11 +1,10 @@ import { MdMenuItem } from "@material/web/menu/menu-item"; -import type { CloseMenuEvent } from "@material/web/menu/menu"; import { css } from "lit"; import { customElement, property } from "lit/decorators"; @customElement("ha-menu-item") export class HaMenuItem extends MdMenuItem { - @property() closeAction?: (ev: CloseMenuEvent) => void; + @property({ attribute: false }) clickAction?: (item?: HTMLElement) => void; static override styles = [ ...super.styles, diff --git a/src/components/ha-menu.ts b/src/components/ha-menu.ts index 55812d8ff919..06e1de186329 100644 --- a/src/components/ha-menu.ts +++ b/src/components/ha-menu.ts @@ -19,9 +19,10 @@ export class HaMenu extends MdMenu { if ( ev.detail.reason.kind === CloseReason.KEYDOWN && ev.detail.reason.key === KeydownCloseKey.ESCAPE - ) + ) { return; - (ev.detail.initiator as HaMenuItem).closeAction?.(ev); + } + (ev.detail.initiator as HaMenuItem).clickAction?.(ev.detail.initiator); } static override styles = [ diff --git a/src/panels/config/automation/ha-automation-picker.ts b/src/panels/config/automation/ha-automation-picker.ts index fb7d08c2598c..b2b64919ac76 100644 --- a/src/panels/config/automation/ha-automation-picker.ts +++ b/src/panels/config/automation/ha-automation-picker.ts @@ -68,6 +68,7 @@ import "../../../components/ha-icon-overflow-menu"; import "../../../components/ha-menu"; import type { HaMenu } from "../../../components/ha-menu"; import "../../../components/ha-menu-item"; +import type { HaMenuItem } from "../../../components/ha-menu-item"; import "../../../components/ha-sub-menu"; import "../../../components/ha-svg-icon"; import { createAreaRegistryEntry } from "../../../data/area_registry"; @@ -822,7 +823,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { - + - +
${this.hass.localize( @@ -840,7 +841,7 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { )}
- +
${this.hass.localize( @@ -848,13 +849,13 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { )}
- +
${this.hass.localize("ui.panel.config.automation.editor.run")}
- +
${this.hass.localize( @@ -863,13 +864,13 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) {
- +
${this.hass.localize("ui.panel.config.automation.picker.duplicate")}
- + - +
${this.hass.localize("ui.panel.config.automation.picker.delete")} @@ -1051,13 +1052,15 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { this._applyFilters(); } - private _showInfo = (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _showInfo = (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; fireEvent(this, "hass-more-info", { entityId: automation.entity_id }); }; - private _showSettings = (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _showSettings = (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; fireEvent(this, "hass-more-info", { entityId: automation.entity_id, @@ -1065,14 +1068,16 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { }); }; - private _runActions = (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _runActions = (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; triggerAutomationActions(this.hass, automation.entity_id); }; - private _editCategory = (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _editCategory = (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; const entityReg = this._entityReg.find( (reg) => reg.entity_id === automation.entity_id @@ -1094,8 +1099,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { }); }; - private _showTrace = (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _showTrace = (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; if (!automation.attributes.id) { showAlertDialog(this, { @@ -1110,8 +1116,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { ); }; - private _toggle = async (ev): Promise => { - const automation = ev.currentTarget.anchorElement.automation; + private _toggle = async (item: HaMenuItem): Promise => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; const service = automation.state === "off" ? "turn_on" : "turn_off"; await this.hass.callService("automation", service, { @@ -1119,8 +1126,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { }); }; - private _deleteConfirm = async (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _deleteConfirm = async (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; showConfirmationDialog(this, { title: this.hass.localize( @@ -1155,8 +1163,9 @@ class HaAutomationPicker extends SubscribeMixin(LitElement) { } } - private _duplicate = async (ev) => { - const automation = ev.currentTarget.anchorElement.automation; + private _duplicate = async (item: HaMenuItem) => { + const automation = ((item.parentElement as HaMenu)!.anchorElement as any)! + .automation; try { const config = await fetchAutomationFileConfig(