mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Fix pickers not getting focus (#14068)
* fix focus pickers * await nextRender instead of setTimeout * use bram's code * Update src/components/ha-target-picker.ts Co-authored-by: Steve Repsher <steverep@users.noreply.github.com> Co-authored-by: Steve Repsher <steverep@users.noreply.github.com>
This commit is contained in:
parent
dad7c43fd2
commit
0972cb4583
@ -221,12 +221,14 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
public open() {
|
public async open() {
|
||||||
this.comboBox?.open();
|
await this.updateComplete;
|
||||||
|
await this.comboBox?.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus() {
|
public async focus() {
|
||||||
this.comboBox?.focus();
|
await this.updateComplete;
|
||||||
|
await this.comboBox?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public hassSubscribe(): UnsubscribeFunc[] {
|
public hassSubscribe(): UnsubscribeFunc[] {
|
||||||
@ -246,7 +248,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
if (
|
if (
|
||||||
(!this._init && this.devices && this.areas && this.entities) ||
|
(!this._init && this.devices && this.areas && this.entities) ||
|
||||||
(changedProps.has("_opened") && this._opened)
|
(this._init && changedProps.has("_opened") && this._opened)
|
||||||
) {
|
) {
|
||||||
this._init = true;
|
this._init = true;
|
||||||
(this.comboBox as any).items = this._getDevices(
|
(this.comboBox as any).items = this._getDevices(
|
||||||
@ -262,9 +264,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this.devices || !this.areas || !this.entities) {
|
|
||||||
return html``;
|
|
||||||
}
|
|
||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@ -107,16 +107,14 @@ export class HaEntityPicker extends LitElement {
|
|||||||
|
|
||||||
@query("ha-combo-box", true) public comboBox!: HaComboBox;
|
@query("ha-combo-box", true) public comboBox!: HaComboBox;
|
||||||
|
|
||||||
public open() {
|
public async open() {
|
||||||
this.updateComplete.then(() => {
|
await this.updateComplete;
|
||||||
this.comboBox?.open();
|
await this.comboBox?.open();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus() {
|
public async focus() {
|
||||||
this.updateComplete.then(() => {
|
await this.updateComplete;
|
||||||
this.comboBox?.focus();
|
await this.comboBox?.focus();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _initedStates = false;
|
private _initedStates = false;
|
||||||
|
@ -116,16 +116,14 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public open() {
|
public async open() {
|
||||||
this.updateComplete.then(() => {
|
await this.updateComplete;
|
||||||
this.comboBox?.open();
|
await this.comboBox?.open();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus() {
|
public async focus() {
|
||||||
this.updateComplete.then(() => {
|
await this.updateComplete;
|
||||||
this.comboBox?.focus();
|
await this.comboBox?.focus();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getAreas = memoizeOne(
|
private _getAreas = memoizeOne(
|
||||||
@ -290,7 +288,7 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) {
|
|||||||
protected updated(changedProps: PropertyValues) {
|
protected updated(changedProps: PropertyValues) {
|
||||||
if (
|
if (
|
||||||
(!this._init && this._devices && this._areas && this._entities) ||
|
(!this._init && this._devices && this._areas && this._entities) ||
|
||||||
(changedProps.has("_opened") && this._opened)
|
(this._init && changedProps.has("_opened") && this._opened)
|
||||||
) {
|
) {
|
||||||
this._init = true;
|
this._init = true;
|
||||||
(this.comboBox as any).items = this._getAreas(
|
(this.comboBox as any).items = this._getAreas(
|
||||||
@ -308,9 +306,6 @@ export class HaAreaPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this._devices || !this._areas || !this._entities) {
|
|
||||||
return html``;
|
|
||||||
}
|
|
||||||
return html`
|
return html`
|
||||||
<ha-combo-box
|
<ha-combo-box
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import "@material/mwc-list/mwc-list-item";
|
import "@material/mwc-list/mwc-list-item";
|
||||||
import { mdiClose, mdiMenuDown, mdiMenuUp } from "@mdi/js";
|
import { mdiClose, mdiMenuDown, mdiMenuUp } from "@mdi/js";
|
||||||
|
import { ComboBoxLitRenderer, comboBoxRenderer } from "@vaadin/combo-box/lit";
|
||||||
import "@vaadin/combo-box/theme/material/vaadin-combo-box-light";
|
import "@vaadin/combo-box/theme/material/vaadin-combo-box-light";
|
||||||
import type {
|
import type {
|
||||||
ComboBoxLight,
|
ComboBoxLight,
|
||||||
@ -16,13 +17,13 @@ import {
|
|||||||
PropertyValues,
|
PropertyValues,
|
||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { ComboBoxLitRenderer, comboBoxRenderer } from "@vaadin/combo-box/lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { HomeAssistant } from "../types";
|
import { HomeAssistant } from "../types";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
import "./ha-textfield";
|
import "./ha-textfield";
|
||||||
|
import type { HaTextField } from "./ha-textfield";
|
||||||
|
|
||||||
registerStyles(
|
registerStyles(
|
||||||
"vaadin-combo-box-item",
|
"vaadin-combo-box-item",
|
||||||
@ -108,18 +109,19 @@ export class HaComboBox extends LitElement {
|
|||||||
|
|
||||||
@query("vaadin-combo-box-light", true) private _comboBox!: ComboBoxLight;
|
@query("vaadin-combo-box-light", true) private _comboBox!: ComboBoxLight;
|
||||||
|
|
||||||
|
@query("ha-textfield", true) private _inputElement!: HaTextField;
|
||||||
|
|
||||||
private _overlayMutationObserver?: MutationObserver;
|
private _overlayMutationObserver?: MutationObserver;
|
||||||
|
|
||||||
public open() {
|
public async open() {
|
||||||
this.updateComplete.then(() => {
|
await this.updateComplete;
|
||||||
this._comboBox?.open();
|
this._comboBox?.open();
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public focus() {
|
public async focus() {
|
||||||
this.updateComplete.then(() => {
|
await this.updateComplete;
|
||||||
this._comboBox?.inputElement?.focus();
|
await this._inputElement?.updateComplete;
|
||||||
});
|
this._inputElement?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback() {
|
public disconnectedCallback() {
|
||||||
|
@ -251,10 +251,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
private async _showPicker(ev) {
|
private async _showPicker(ev) {
|
||||||
this._addMode = ev.currentTarget.type;
|
this._addMode = ev.currentTarget.type;
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
setTimeout(() => {
|
await this._inputElement?.focus();
|
||||||
this._inputElement?.open();
|
await this._inputElement?.open();
|
||||||
this._inputElement?.focus();
|
|
||||||
}, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _renderChip(
|
private _renderChip(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user