Fix ha-selector-object not updating in the ui when new value is pushed from the parent (#15022)

Co-authored-by: Bram Kragten <mail@bramkragten.nl>
fixes undefined
This commit is contained in:
karwosts 2023-01-25 02:09:58 -08:00 committed by GitHub
parent 0bbe6151ed
commit 3675a2b013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,10 @@
import { html, LitElement } from "lit";
import { customElement, property } from "lit/decorators";
import { html, LitElement, PropertyValues } from "lit";
import { customElement, property, query } from "lit/decorators";
import { fireEvent } from "../../common/dom/fire_event";
import { HomeAssistant } from "../../types";
import "../ha-yaml-editor";
import "../ha-input-helper-text";
import type { HaYamlEditor } from "../ha-yaml-editor";
@customElement("ha-selector-object")
export class HaObjectSelector extends LitElement {
@ -21,6 +22,10 @@ export class HaObjectSelector extends LitElement {
@property({ type: Boolean }) public required = true;
@query("ha-yaml-editor", true) private _yamlEditor!: HaYamlEditor;
private _valueChangedFromChild = false;
protected render() {
return html`<ha-yaml-editor
.hass=${this.hass}
@ -36,7 +41,16 @@ export class HaObjectSelector extends LitElement {
: ""} `;
}
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (changedProps.has("value") && !this._valueChangedFromChild) {
this._yamlEditor.setValue(this.value);
}
this._valueChangedFromChild = false;
}
private _handleChange(ev) {
this._valueChangedFromChild = true;
const value = ev.target.value;
if (!ev.target.isValid) {
return;