diff --git a/src/panels/lovelace/cards/hui-conditional-card.ts b/src/panels/lovelace/cards/hui-conditional-card.ts index 0dbe1aa687..33a3c03510 100644 --- a/src/panels/lovelace/cards/hui-conditional-card.ts +++ b/src/panels/lovelace/cards/hui-conditional-card.ts @@ -30,7 +30,12 @@ class HuiConditionalCard extends HuiConditionalBase implements LovelaceCard { throw new Error("No card configured."); } + if (this._element && this._element.parentElement) { + this.removeChild(this._element); + } + this._element = createCardElement(config.card) as LovelaceCard; + this.appendChild(this._element); } public getCardSize(): number { diff --git a/src/panels/lovelace/components/hui-conditional-base.ts b/src/panels/lovelace/components/hui-conditional-base.ts index 14edcc629f..a3a1387b7d 100644 --- a/src/panels/lovelace/components/hui-conditional-base.ts +++ b/src/panels/lovelace/components/hui-conditional-base.ts @@ -30,26 +30,19 @@ export class HuiConditionalBase extends UpdatingElement { throw new Error("Conditions are invalid."); } - if (this._element && this._element.parentElement) { - this.removeChild(this._element); - } - this._config = config; + this.style.display = "none"; } protected update(): void { - if (!this._element || !this.hass) { + if (!this._element || !this.hass || !this._config) { return; } - const visible = - this._config && checkConditionsMet(this._config.conditions, this.hass); + const visible = checkConditionsMet(this._config.conditions, this.hass); if (visible) { this._element.hass = this.hass; - if (!this._element.parentElement) { - this.appendChild(this._element); - } } this.style.setProperty("display", visible ? "" : "none"); diff --git a/src/panels/lovelace/special-rows/hui-conditional-row.ts b/src/panels/lovelace/special-rows/hui-conditional-row.ts index e735f13870..e7caca11e3 100644 --- a/src/panels/lovelace/special-rows/hui-conditional-row.ts +++ b/src/panels/lovelace/special-rows/hui-conditional-row.ts @@ -13,7 +13,12 @@ class HuiConditionalRow extends HuiConditionalBase implements LovelaceRow { throw new Error("No row configured."); } + if (this._element && this._element.parentElement) { + this.removeChild(this._element); + } + this._element = createRowElement(config.row) as LovelaceRow; + this.appendChild(this._element); } }