Fix changing view type (#8688)

This commit is contained in:
Bram Kragten 2021-03-25 14:21:38 +01:00 committed by GitHub
parent af5b22a265
commit 57e535c2c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -51,6 +51,8 @@ export class HUIView extends UpdatingElement {
@internalProperty() private _badges: LovelaceBadge[] = [];
private _layoutElementType?: string;
private _layoutElement?: LovelaceViewElement;
// Public to make demo happy
@ -116,8 +118,15 @@ export class HUIView extends UpdatingElement {
};
}
if (configChanged && !this._layoutElement) {
let replace = false;
if (
configChanged &&
(!this._layoutElement || this._layoutElementType !== viewConfig!.type)
) {
replace = true;
this._layoutElement = createViewElement(viewConfig!);
this._layoutElementType = viewConfig!.type;
this._layoutElement.addEventListener("ll-create-card", () => {
showCreateCardDialog(this, {
lovelaceConfig: this.lovelace!.config,
@ -195,7 +204,10 @@ export class HUIView extends UpdatingElement {
);
}
if (this._layoutElement && !this.lastChild) {
if (this._layoutElement && replace) {
while (this.lastChild) {
this.removeChild(this.lastChild);
}
this.appendChild(this._layoutElement);
}
}