diff --git a/src/components/device/ha-device-picker.ts b/src/components/device/ha-device-picker.ts index b387be1115..d93e717b27 100644 --- a/src/components/device/ha-device-picker.ts +++ b/src/components/device/ha-device-picker.ts @@ -221,12 +221,14 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) { } ); - public open() { - this.comboBox?.open(); + public async open() { + await this.updateComplete; + await this.comboBox?.open(); } - public focus() { - this.comboBox?.focus(); + public async focus() { + await this.updateComplete; + await this.comboBox?.focus(); } public hassSubscribe(): UnsubscribeFunc[] { @@ -246,7 +248,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) { protected updated(changedProps: PropertyValues) { if ( (!this._init && this.devices && this.areas && this.entities) || - (changedProps.has("_opened") && this._opened) + (this._init && changedProps.has("_opened") && this._opened) ) { this._init = true; (this.comboBox as any).items = this._getDevices( @@ -262,9 +264,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) { } protected render(): TemplateResult { - if (!this.devices || !this.areas || !this.entities) { - return html``; - } return html` { - this.comboBox?.open(); - }); + public async open() { + await this.updateComplete; + await this.comboBox?.open(); } - public focus() { - this.updateComplete.then(() => { - this.comboBox?.focus(); - }); + public async focus() { + await this.updateComplete; + await this.comboBox?.focus(); } private _initedStates = false; diff --git a/src/components/ha-area-picker.ts b/src/components/ha-area-picker.ts index 6a56868bd2..270a7ed8c2 100644 --- a/src/components/ha-area-picker.ts +++ b/src/components/ha-area-picker.ts @@ -116,16 +116,14 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) { ]; } - public open() { - this.updateComplete.then(() => { - this.comboBox?.open(); - }); + public async open() { + await this.updateComplete; + await this.comboBox?.open(); } - public focus() { - this.updateComplete.then(() => { - this.comboBox?.focus(); - }); + public async focus() { + await this.updateComplete; + await this.comboBox?.focus(); } private _getAreas = memoizeOne( @@ -290,7 +288,7 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) { protected updated(changedProps: PropertyValues) { if ( (!this._init && this._devices && this._areas && this._entities) || - (changedProps.has("_opened") && this._opened) + (this._init && changedProps.has("_opened") && this._opened) ) { this._init = true; (this.comboBox as any).items = this._getAreas( @@ -308,9 +306,6 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) { } protected render(): TemplateResult { - if (!this._devices || !this._areas || !this._entities) { - return html``; - } return html` { - this._comboBox?.open(); - }); + public async open() { + await this.updateComplete; + this._comboBox?.open(); } - public focus() { - this.updateComplete.then(() => { - this._comboBox?.inputElement?.focus(); - }); + public async focus() { + await this.updateComplete; + await this._inputElement?.updateComplete; + this._inputElement?.focus(); } public disconnectedCallback() { diff --git a/src/components/ha-target-picker.ts b/src/components/ha-target-picker.ts index 0f6ee2f41e..3ad3baf159 100644 --- a/src/components/ha-target-picker.ts +++ b/src/components/ha-target-picker.ts @@ -251,10 +251,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) { private async _showPicker(ev) { this._addMode = ev.currentTarget.type; await this.updateComplete; - setTimeout(() => { - this._inputElement?.open(); - this._inputElement?.focus(); - }, 0); + await this._inputElement?.focus(); + await this._inputElement?.open(); } private _renderChip(