diff --git a/src/components/ha-menu-button.ts b/src/components/ha-menu-button.ts index 3bb80a0e04..2246dd136b 100644 --- a/src/components/ha-menu-button.ts +++ b/src/components/ha-menu-button.ts @@ -73,25 +73,25 @@ class HaMenuButton extends LitElement { return; } - const oldHass = changedProps.get("hass") as HomeAssistant | undefined; + const oldHass = changedProps.has("hass") + ? (changedProps.get("hass") as HomeAssistant | undefined) + : this.hass; + const oldNarrow = changedProps.has("narrow") + ? (changedProps.get("narrow") as boolean | undefined) + : this.narrow; - let oldNarrow: boolean | undefined; - let newNarrow: boolean | undefined; - if (changedProps.has("narrow")) { - oldNarrow = changedProps.get("narrow"); - newNarrow = this.narrow; - } else if (oldHass) { - oldNarrow = oldHass.dockedSidebar === "always_hidden"; - newNarrow = this.hass.dockedSidebar === "always_hidden"; - } + const oldShowButton = + oldNarrow || oldHass?.dockedSidebar === "always_hidden"; + const showButton = + this.narrow || this.hass.dockedSidebar === "always_hidden"; - if (oldNarrow === newNarrow) { + if (oldShowButton === showButton) { return; } - this.style.display = newNarrow || this._alwaysVisible ? "initial" : "none"; + this.style.display = showButton || this._alwaysVisible ? "initial" : "none"; - if (!newNarrow) { + if (!showButton) { if (this._unsubNotifications) { this._unsubNotifications(); this._unsubNotifications = undefined;