Always render conditional elements (#5398)

This commit is contained in:
Bram Kragten 2020-04-01 19:15:48 +02:00 committed by GitHub
parent 087492fc0b
commit e1b48dd2a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -30,7 +30,12 @@ class HuiConditionalCard extends HuiConditionalBase implements LovelaceCard {
throw new Error("No card configured."); throw new Error("No card configured.");
} }
if (this._element && this._element.parentElement) {
this.removeChild(this._element);
}
this._element = createCardElement(config.card) as LovelaceCard; this._element = createCardElement(config.card) as LovelaceCard;
this.appendChild(this._element);
} }
public getCardSize(): number { public getCardSize(): number {

View File

@ -30,26 +30,19 @@ export class HuiConditionalBase extends UpdatingElement {
throw new Error("Conditions are invalid."); throw new Error("Conditions are invalid.");
} }
if (this._element && this._element.parentElement) {
this.removeChild(this._element);
}
this._config = config; this._config = config;
this.style.display = "none";
} }
protected update(): void { protected update(): void {
if (!this._element || !this.hass) { if (!this._element || !this.hass || !this._config) {
return; return;
} }
const visible = const visible = checkConditionsMet(this._config.conditions, this.hass);
this._config && checkConditionsMet(this._config.conditions, this.hass);
if (visible) { if (visible) {
this._element.hass = this.hass; this._element.hass = this.hass;
if (!this._element.parentElement) {
this.appendChild(this._element);
}
} }
this.style.setProperty("display", visible ? "" : "none"); this.style.setProperty("display", visible ? "" : "none");

View File

@ -13,7 +13,12 @@ class HuiConditionalRow extends HuiConditionalBase implements LovelaceRow {
throw new Error("No row configured."); throw new Error("No row configured.");
} }
if (this._element && this._element.parentElement) {
this.removeChild(this._element);
}
this._element = createRowElement(config.row) as LovelaceRow; this._element = createRowElement(config.row) as LovelaceRow;
this.appendChild(this._element);
} }
} }