mirror of
https://github.com/home-assistant/frontend.git
synced 2025-11-09 02:49:51 +00:00
Convert entity picker to ha-combo (#11560)
* Convert entity picker to ha-combo * Update ha-entity-picker.ts * Handle empty better * Clear value when no device/area/entity
This commit is contained in:
@@ -38,7 +38,7 @@ export type HaDevicePickerDeviceFilterFunc = (
|
||||
) => boolean;
|
||||
|
||||
const rowRenderer: ComboBoxLitRenderer<Device> = (item) => html`<mwc-list-item
|
||||
twoline
|
||||
.twoline=${!!item.area}
|
||||
>
|
||||
<span>${item.name}</span>
|
||||
<span slot="secondary">${item.area}</span>
|
||||
@@ -105,7 +105,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
if (!devices.length) {
|
||||
return [
|
||||
{
|
||||
id: "",
|
||||
id: "no_devices",
|
||||
area: "",
|
||||
name: this.hass.localize("ui.components.device-picker.no_devices"),
|
||||
},
|
||||
@@ -201,7 +201,7 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
if (!outputDevices.length) {
|
||||
return [
|
||||
{
|
||||
id: "",
|
||||
id: "no_devices",
|
||||
area: "",
|
||||
name: this.hass.localize("ui.components.device-picker.no_match"),
|
||||
},
|
||||
@@ -270,7 +270,6 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
.renderer=${rowRenderer}
|
||||
.disabled=${this.disabled}
|
||||
item-value-path="id"
|
||||
item-id-path="id"
|
||||
item-label-path="name"
|
||||
@opened-changed=${this._openedChanged}
|
||||
@value-changed=${this._deviceChanged}
|
||||
@@ -284,7 +283,11 @@ export class HaDevicePicker extends SubscribeMixin(LitElement) {
|
||||
|
||||
private _deviceChanged(ev: PolymerChangedEvent<string>) {
|
||||
ev.stopPropagation();
|
||||
const newValue = ev.detail.value;
|
||||
let newValue = ev.detail.value;
|
||||
|
||||
if (newValue === "no_devices") {
|
||||
newValue = "";
|
||||
}
|
||||
|
||||
if (newValue !== this._value) {
|
||||
this._setValue(newValue);
|
||||
|
||||
Reference in New Issue
Block a user