diff --git a/src/components/ha-sidebar.ts b/src/components/ha-sidebar.ts index 8b9d939aef12..01e84f32ca8c 100644 --- a/src/components/ha-sidebar.ts +++ b/src/components/ha-sidebar.ts @@ -24,16 +24,9 @@ import "@polymer/paper-listbox/paper-listbox"; import type { UnsubscribeFunc } from "home-assistant-js-websocket"; import type { CSSResult, CSSResultGroup, PropertyValues } from "lit"; import { LitElement, css, html, nothing } from "lit"; -import { - customElement, - eventOptions, - property, - query, - state, -} from "lit/decorators"; +import { customElement, eventOptions, property, state } from "lit/decorators"; import { classMap } from "lit/directives/class-map"; import memoizeOne from "memoize-one"; -import type { PaperListboxElement } from "@polymer/paper-listbox"; import { storage } from "../common/decorators/storage"; import { fireEvent } from "../common/dom/fire_event"; import { toggleAttribute } from "../common/dom/toggle_attribute"; @@ -55,6 +48,7 @@ import "./ha-menu-button"; import "./ha-sortable"; import "./ha-svg-icon"; import "./user/ha-user-badge"; +import { preventDefault } from "../common/dom/prevent_default"; const SHOW_AFTER_SPACER = ["config", "developer-tools"]; @@ -203,8 +197,6 @@ class HaSidebar extends SubscribeMixin(LitElement) { @state() private _issuesCount = 0; - @query("paper-listbox", true) private _sidebar!: PaperListboxElement; - private _mouseLeaveTimeout?: number; private _tooltipHideTimeout?: number; @@ -296,10 +288,6 @@ class HaSidebar extends SubscribeMixin(LitElement) { protected firstUpdated(changedProps: PropertyValues) { super.firstUpdated(changedProps); this._subscribePersistentNotifications(); - - window.addEventListener("hass-reset-sidebar", (ev) => { - this._sidebar.selected = ev.detail; - }); } private _subscribePersistentNotifications(): void { @@ -417,6 +405,7 @@ class HaSidebar extends SubscribeMixin(LitElement) { @focusout=${this._listboxFocusOut} @scroll=${this._listboxScroll} @keydown=${this._listboxKeydown} + @iron-activate=${preventDefault} > ${this.editMode ? this._renderPanelsEdit(beforeSpacer) @@ -1137,8 +1126,4 @@ declare global { interface HTMLElementTagNameMap { "ha-sidebar": HaSidebar; } - - interface HASSDomEvents { - "hass-reset-sidebar": string; - } } diff --git a/src/mixins/prevent-unsaved-mixin.ts b/src/mixins/prevent-unsaved-mixin.ts index 7974d3f940b7..a1c7b5af9219 100644 --- a/src/mixins/prevent-unsaved-mixin.ts +++ b/src/mixins/prevent-unsaved-mixin.ts @@ -1,7 +1,6 @@ import type { LitElement, PropertyValues } from "lit"; -import type { Constructor } from "../types"; import { isNavigationClick } from "../common/dom/is-navigation-click"; -import { fireEvent } from "../common/dom/fire_event"; +import type { Constructor } from "../types"; export const PreventUnsavedMixin = >( superClass: T @@ -21,8 +20,6 @@ export const PreventUnsavedMixin = >( const newEvent = new MouseEvent(e.type, e); target.dispatchEvent(newEvent); } - } else { - fireEvent(this, "hass-reset-sidebar", this.getPanel()); } }; @@ -36,7 +33,7 @@ export const PreventUnsavedMixin = >( public willUpdate(changedProperties: PropertyValues): void { super.willUpdate(changedProperties); - if (this.isDirty()) { + if (this.isDirty) { window.addEventListener("click", this._handleClick, true); window.addEventListener("beforeunload", this._handleUnload); } else { @@ -50,15 +47,11 @@ export const PreventUnsavedMixin = >( this._removeListeners(); } - protected isDirty(): boolean { + protected get isDirty(): boolean { return false; } protected async promptDiscardChanges(): Promise { return true; } - - protected getPanel(): string { - return "config"; - } }; diff --git a/src/panels/config/automation/ha-automation-editor.ts b/src/panels/config/automation/ha-automation-editor.ts index f6863e35605b..6f0a8092577e 100644 --- a/src/panels/config/automation/ha-automation-editor.ts +++ b/src/panels/config/automation/ha-automation-editor.ts @@ -850,7 +850,7 @@ export class HaAutomationEditor extends PreventUnsavedMixin( }; } - protected isDirty() { + protected get isDirty() { return this._dirty; } diff --git a/src/panels/config/scene/ha-scene-editor.ts b/src/panels/config/scene/ha-scene-editor.ts index e6b0e25d3451..23eaea460134 100644 --- a/src/panels/config/scene/ha-scene-editor.ts +++ b/src/panels/config/scene/ha-scene-editor.ts @@ -1226,7 +1226,7 @@ export class HaSceneEditor extends PreventUnsavedMixin( }); } - protected isDirty() { + protected get isDirty() { return this._dirty; } diff --git a/src/panels/config/script/ha-script-editor.ts b/src/panels/config/script/ha-script-editor.ts index a9f59bd195d5..9e65ec9b3370 100644 --- a/src/panels/config/script/ha-script-editor.ts +++ b/src/panels/config/script/ha-script-editor.ts @@ -816,7 +816,7 @@ export class HaScriptEditor extends PreventUnsavedMixin( }; } - protected isDirty() { + protected get isDirty() { return this._dirty; }