Don't update device picker while open (#7903)

This commit is contained in:
Bram Kragten 2020-12-04 12:05:01 +01:00 committed by GitHub
parent 34eb4d974d
commit b79c03433e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,6 +12,8 @@ import {
html, html,
LitElement, LitElement,
property, property,
PropertyValues,
query,
TemplateResult, TemplateResult,
} from "lit-element"; } from "lit-element";
import memoizeOne from "memoize-one"; import memoizeOne from "memoize-one";
@ -111,6 +113,8 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
@property({ type: Boolean }) @property({ type: Boolean })
private _opened?: boolean; private _opened?: boolean;
@query("vaadin-combo-box-light", true) private _comboBox!: HTMLElement;
public open() { public open() {
this.updateComplete.then(() => { this.updateComplete.then(() => {
(this.shadowRoot?.querySelector("vaadin-combo-box-light") as any)?.open(); (this.shadowRoot?.querySelector("vaadin-combo-box-light") as any)?.open();
@ -246,25 +250,29 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
]; ];
} }
protected render(): TemplateResult { protected updated(changedProps: PropertyValues) {
if (!this.devices || !this.areas || !this.entities) { if (changedProps.has("_opened") && this._opened) {
return html``; (this._comboBox as any).items = this._getDevices(
} this.devices!,
const devices = this._getDevices( this.areas!,
this.devices, this.entities!,
this.areas,
this.entities,
this.includeDomains, this.includeDomains,
this.excludeDomains, this.excludeDomains,
this.includeDeviceClasses, this.includeDeviceClasses,
this.deviceFilter this.deviceFilter
); );
}
}
protected render(): TemplateResult {
if (!this.devices || !this.areas || !this.entities) {
return html``;
}
return html` return html`
<vaadin-combo-box-light <vaadin-combo-box-light
item-value-path="id" item-value-path="id"
item-id-path="id" item-id-path="id"
item-label-path="name" item-label-path="name"
.items=${devices}
.value=${this._value} .value=${this._value}
.renderer=${rowRenderer} .renderer=${rowRenderer}
@opened-changed=${this._openedChanged} @opened-changed=${this._openedChanged}
@ -296,8 +304,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
</ha-icon-button> </ha-icon-button>
` `
: ""} : ""}
${devices.length > 0
? html`
<ha-icon-button <ha-icon-button
aria-label=${this.hass.localize( aria-label=${this.hass.localize(
"ui.components.device-picker.show_devices" "ui.components.device-picker.show_devices"
@ -308,8 +314,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
> >
Toggle Toggle
</ha-icon-button> </ha-icon-button>
`
: ""}
</paper-input> </paper-input>
</vaadin-combo-box-light> </vaadin-combo-box-light>
`; `;