Fix ha-menu-button not hidden (#17102)

This commit is contained in:
Bram Kragten 2023-06-29 15:09:58 +02:00 committed by GitHub
parent b5eb18e163
commit a227d7a2cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,6 @@
import { mdiMenu } from "@mdi/js"; import { mdiMenu } from "@mdi/js";
import { UnsubscribeFunc } from "home-assistant-js-websocket"; import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit"; import { css, CSSResultGroup, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import { subscribeNotifications } from "../data/persistent_notification"; import { subscribeNotifications } from "../data/persistent_notification";
@ -17,6 +17,8 @@ class HaMenuButton extends LitElement {
@state() private _hasNotifications = false; @state() private _hasNotifications = false;
@state() private _show = false;
private _alwaysVisible = false; private _alwaysVisible = false;
private _attachNotifOnConnect = false; private _attachNotifOnConnect = false;
@ -40,7 +42,10 @@ class HaMenuButton extends LitElement {
} }
} }
protected render(): TemplateResult { protected render() {
if (!this._show) {
return nothing;
}
const hasNotifications = const hasNotifications =
this._hasNotifications && this._hasNotifications &&
(this.narrow || this.hass.dockedSidebar === "always_hidden"); (this.narrow || this.hass.dockedSidebar === "always_hidden");
@ -66,8 +71,8 @@ class HaMenuButton extends LitElement {
(Number((window.parent as any).frontendVersion) || 0) < 20190710; (Number((window.parent as any).frontendVersion) || 0) < 20190710;
} }
protected updated(changedProps) { protected willUpdate(changedProps) {
super.updated(changedProps); super.willUpdate(changedProps);
if (!changedProps.has("narrow") && !changedProps.has("hass")) { if (!changedProps.has("narrow") && !changedProps.has("hass")) {
return; return;
@ -85,11 +90,11 @@ class HaMenuButton extends LitElement {
const showButton = const showButton =
this.narrow || this.hass.dockedSidebar === "always_hidden"; this.narrow || this.hass.dockedSidebar === "always_hidden";
if (oldShowButton === showButton) { if (this.hasUpdated && oldShowButton === showButton) {
return; return;
} }
this.style.display = showButton || this._alwaysVisible ? "initial" : "none"; this._show = showButton || this._alwaysVisible;
if (!showButton) { if (!showButton) {
if (this._unsubNotifications) { if (this._unsubNotifications) {