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 updated(changedProps: PropertyValues) {
if (changedProps.has("_opened") && this._opened) {
(this._comboBox as any).items = this._getDevices(
this.devices!,
this.areas!,
this.entities!,
this.includeDomains,
this.excludeDomains,
this.includeDeviceClasses,
this.deviceFilter
);
}
}
protected render(): TemplateResult { protected render(): TemplateResult {
if (!this.devices || !this.areas || !this.entities) { if (!this.devices || !this.areas || !this.entities) {
return html``; return html``;
} }
const devices = this._getDevices(
this.devices,
this.areas,
this.entities,
this.includeDomains,
this.excludeDomains,
this.includeDeviceClasses,
this.deviceFilter
);
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,20 +304,16 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
</ha-icon-button> </ha-icon-button>
` `
: ""} : ""}
${devices.length > 0 <ha-icon-button
? html` aria-label=${this.hass.localize(
<ha-icon-button "ui.components.device-picker.show_devices"
aria-label=${this.hass.localize( )}
"ui.components.device-picker.show_devices" slot="suffix"
)} class="toggle-button"
slot="suffix" .icon=${this._opened ? "hass:menu-up" : "hass:menu-down"}
class="toggle-button" >
.icon=${this._opened ? "hass:menu-up" : "hass:menu-down"} Toggle
> </ha-icon-button>
Toggle
</ha-icon-button>
`
: ""}
</paper-input> </paper-input>
</vaadin-combo-box-light> </vaadin-combo-box-light>
`; `;