From 1ba43a2fbb0e11ccf3395ebde8c7242b0f8cc863 Mon Sep 17 00:00:00 2001 From: Wendelin Date: Thu, 23 Oct 2025 13:07:09 +0200 Subject: [PATCH] Improve labels picker --- src/components/ha-generic-picker.ts | 62 +++++++------ src/components/ha-label-picker.ts | 12 ++- src/components/ha-labels-picker.ts | 92 +++++++++---------- .../areas/dialog-area-registry-detail.ts | 23 ++--- 4 files changed, 101 insertions(+), 88 deletions(-) diff --git a/src/components/ha-generic-picker.ts b/src/components/ha-generic-picker.ts index f79c83ae79..46feec24f2 100644 --- a/src/components/ha-generic-picker.ts +++ b/src/components/ha-generic-picker.ts @@ -96,33 +96,38 @@ export class HaGenericPicker extends LitElement { ? html`` : nothing}
- ${this.addButtonLabel && !this.value - ? html` - - ${this.addButtonLabel} - ` - : html` - `} +
+ + ${this.addButtonLabel && !this.value + ? html` + + ${this.addButtonLabel} + ` + : html` + `} + +
${!this._openedNarrow && (this._pickerWrapperOpen || this._opened) ? html` ; + @query("ha-generic-picker") private _picker?: HaGenericPicker; public async open() { @@ -226,6 +235,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) { .valueRenderer=${valueRenderer} @value-changed=${this._valueChanged} > + `; } diff --git a/src/components/ha-labels-picker.ts b/src/components/ha-labels-picker.ts index 726d424b2f..c248592daa 100644 --- a/src/components/ha-labels-picker.ts +++ b/src/components/ha-labels-picker.ts @@ -1,3 +1,4 @@ +import { mdiPlaylistPlus } from "@mdi/js"; import type { HassEntity, UnsubscribeFunc } from "home-assistant-js-websocket"; import type { TemplateResult } from "lit"; import { LitElement, css, html, nothing } from "lit"; @@ -123,42 +124,6 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) { ); return html` ${this.label ? html`` : nothing} - - ${labels?.length - ? repeat( - labels, - (label) => label?.label_id, - (label) => { - const color = label?.color - ? computeCssColor(label.color) - : undefined; - return html` - - ${label?.icon - ? html`` - : nothing} - - `; - } - ) - : html`
- ${this.hass.localize("ui.components.label-picker.labels")} -
`} -
+ + ${labels?.length + ? repeat( + labels, + (label) => label?.label_id, + (label) => { + const color = label?.color + ? computeCssColor(label.color) + : undefined; + return html` + + ${label?.icon + ? html`` + : nothing} + + `; + } + ) + : nothing} + + + ${this.hass.localize("ui.components.label-picker.add")} + + `; } @@ -210,15 +216,8 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) { } private _openPicker(ev: Event) { - const labels = this._sortedLabels( - this.value, - this._labels, - this.hass.locale.language - ); - if (!labels?.length) { - ev.stopPropagation(); - this.labelPicker.open(); - } + ev.stopPropagation(); + this.labelPicker.open(); } static styles = css` @@ -230,9 +229,6 @@ export class HaLabelsPicker extends SubscribeMixin(LitElement) { border-top-left-radius: var(--ha-border-radius-sm); padding: var(--ha-space-3); } - ha-chip-set.clickable { - cursor: pointer; - } .placeholder { color: var(--mdc-text-field-label-ink-color); display: flex; diff --git a/src/panels/config/areas/dialog-area-registry-detail.ts b/src/panels/config/areas/dialog-area-registry-detail.ts index 507f5cf7ac..83ef8c8943 100644 --- a/src/panels/config/areas/dialog-area-registry-detail.ts +++ b/src/panels/config/areas/dialog-area-registry-detail.ts @@ -1,34 +1,34 @@ +import type { HassEntity } from "home-assistant-js-websocket"; import type { CSSResultGroup } from "lit"; import { css, html, LitElement, nothing } from "lit"; import { property, state } from "lit/decorators"; -import type { HassEntity } from "home-assistant-js-websocket"; import { fireEvent } from "../../../common/dom/fire_event"; +import "../../../components/entity/ha-entity-picker"; +import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker"; import "../../../components/ha-alert"; import "../../../components/ha-aliases-editor"; +import { createCloseHeading } from "../../../components/ha-dialog"; +import "../../../components/ha-floor-picker"; +import "../../../components/ha-icon-picker"; +import "../../../components/ha-labels-picker"; import "../../../components/ha-picture-upload"; import type { HaPictureUpload } from "../../../components/ha-picture-upload"; import "../../../components/ha-settings-row"; -import "../../../components/ha-icon-picker"; -import "../../../components/ha-floor-picker"; -import "../../../components/entity/ha-entity-picker"; -import type { HaEntityPicker } from "../../../components/entity/ha-entity-picker"; import "../../../components/ha-textfield"; -import "../../../components/ha-labels-picker"; import type { AreaRegistryEntry, AreaRegistryEntryMutableParams, } from "../../../data/area_registry"; import { deleteAreaRegistryEntry } from "../../../data/area_registry"; -import type { CropOptions } from "../../../dialogs/image-cropper-dialog/show-image-cropper-dialog"; -import { haStyleDialog } from "../../../resources/styles"; -import type { HomeAssistant, ValueChangedEvent } from "../../../types"; -import type { AreaRegistryDetailDialogParams } from "./show-dialog-area-registry-detail"; import { SENSOR_DEVICE_CLASS_HUMIDITY, SENSOR_DEVICE_CLASS_TEMPERATURE, } from "../../../data/sensor"; import { showConfirmationDialog } from "../../../dialogs/generic/show-dialog-box"; -import { createCloseHeading } from "../../../components/ha-dialog"; +import type { CropOptions } from "../../../dialogs/image-cropper-dialog/show-image-cropper-dialog"; +import { haStyleDialog } from "../../../resources/styles"; +import type { HomeAssistant, ValueChangedEvent } from "../../../types"; +import type { AreaRegistryDetailDialogParams } from "./show-dialog-area-registry-detail"; const cropOptions: CropOptions = { round: false, @@ -139,6 +139,7 @@ class DialogAreaDetail extends LitElement { >