Fix element rendering.
This commit is contained in:
@@ -56,6 +56,9 @@ class FrigateCardElementsCore extends LitElement {
|
||||
@property({ attribute: false })
|
||||
protected elements: PictureElements;
|
||||
|
||||
@property({ attribute: false })
|
||||
protected view?: View;
|
||||
|
||||
protected _root: HTMLElement | null = null;
|
||||
protected _hass!: HomeAssistant & ExtendedHomeAssistant;
|
||||
|
||||
@@ -72,7 +75,7 @@ class FrigateCardElementsCore extends LitElement {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected _createRoot(): void {
|
||||
protected _createRoot(): HTMLElement {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const elementConstructor = customElements.get('hui-conditional-element') as any;
|
||||
if (!elementConstructor) {
|
||||
@@ -92,16 +95,16 @@ class FrigateCardElementsCore extends LitElement {
|
||||
console.error(e, (e as Error).stack);
|
||||
throw new Error(localize('error.invalid_elements_config'));
|
||||
}
|
||||
this._root = element;
|
||||
return element;
|
||||
}
|
||||
|
||||
protected render(): TemplateResult | void {
|
||||
if (!this._root) {
|
||||
try {
|
||||
this._createRoot();
|
||||
} catch (e) {
|
||||
return dispatchErrorMessageEvent(this, (e as Error).message);
|
||||
}
|
||||
try {
|
||||
// Recreate the root on each render to ensure conditional ancestors
|
||||
// re-fire events as necessary.
|
||||
this._root = this._createRoot();
|
||||
} catch (e) {
|
||||
return dispatchErrorMessageEvent(this, (e as Error).message);
|
||||
}
|
||||
return html`${this._root || ''}`;
|
||||
}
|
||||
@@ -113,6 +116,9 @@ export class FrigateCardElements extends LitElement {
|
||||
@property({ attribute: false })
|
||||
protected elements: PictureElements;
|
||||
|
||||
@property({ attribute: false })
|
||||
protected view!: View;
|
||||
|
||||
protected _hass!: HomeAssistant & ExtendedHomeAssistant;
|
||||
|
||||
@query('frigate-card-elements-core')
|
||||
@@ -168,6 +174,7 @@ export class FrigateCardElements extends LitElement {
|
||||
protected render(): TemplateResult {
|
||||
return html` <frigate-card-elements-core
|
||||
.hass=${this._hass}
|
||||
.view=${this.view}
|
||||
.elements=${this.elements}
|
||||
>
|
||||
</frigate-card-elements-core>`;
|
||||
|
||||
@@ -33,16 +33,6 @@ export class FrigateCardMenu extends LitElement {
|
||||
@property({ attribute: false })
|
||||
public buttons: MenuButton[] = [];
|
||||
|
||||
public addButton(button: MenuButton): void {
|
||||
if (!this.buttons.includes(button)) {
|
||||
this.buttons = [...this.buttons, button];
|
||||
}
|
||||
}
|
||||
|
||||
public removeButton(target: MenuButton): void {
|
||||
this.buttons = this.buttons.filter(button => button != target);
|
||||
}
|
||||
|
||||
// Call the callback.
|
||||
protected _callAction(ev: CustomEvent, button: MenuButton): void {
|
||||
if (this.menuMode.startsWith('hidden-')) {
|
||||
|
||||
Reference in New Issue
Block a user