Fix background theme in Lovelace view

This commit is contained in:
Bram Kragten 2023-04-06 17:31:55 +02:00
parent 0364c5e493
commit d8ddbefcf6
No known key found for this signature in database
GPG Key ID: FBE2DFDB363EF55B
1 changed files with 33 additions and 0 deletions

View File

@ -104,6 +104,36 @@ export class HUIView extends ReactiveElement {
return this;
}
public connectedCallback() {
super.connectedCallback();
this._applyBackgroundTheme();
}
private _applyBackgroundTheme() {
if (this._viewConfigTheme) {
const theme = this.hass.themes.themes[this._viewConfigTheme];
if (theme["lovelace-background"]) {
this.parentElement?.style.setProperty(
"--lovelace-background",
theme["lovelace-background"]
);
} else {
this.parentElement?.style.removeProperty("--lovelace-background");
}
if (theme["primary-background-color"]) {
this.parentElement?.style.setProperty(
"--primary-background-color",
theme["primary-background-color"]
);
} else {
this.parentElement?.style.removeProperty("--primary-background-color");
}
} else {
this.parentElement?.style.removeProperty("--lovelace-background");
this.parentElement?.style.removeProperty("--primary-background-color");
}
}
public willUpdate(changedProperties: PropertyValues): void {
super.willUpdate(changedProperties);
@ -166,6 +196,7 @@ export class HUIView extends ReactiveElement {
this.hass.selectedTheme !== oldHass.selectedTheme
) {
applyThemesOnElement(this, this.hass.themes, this._viewConfigTheme);
this._applyBackgroundTheme();
}
}
if (changedProperties.has("narrow")) {
@ -225,6 +256,8 @@ export class HUIView extends ReactiveElement {
applyThemesOnElement(this, this.hass.themes, viewConfig.theme);
this._viewConfigTheme = viewConfig.theme;
this._applyBackgroundTheme();
if (addLayoutElement) {
while (this.lastChild) {
this.removeChild(this.lastChild);