From 81cb48316363f2b87e2e6494e19413dd18f4b36d Mon Sep 17 00:00:00 2001 From: ildar170975 <71872483+ildar170975@users.noreply.github.com> Date: Mon, 15 Dec 2025 11:54:12 +0300 Subject: [PATCH] Generic picker: show a label for area, category, language (#28236) Co-authored-by: Aidan Timson --- src/components/ha-area-picker.ts | 14 +++++++++++++- src/components/ha-combo-box-item.ts | 11 +++++++++++ src/components/ha-generic-picker.ts | 4 ++++ src/components/ha-language-picker.ts | 1 + src/components/ha-picker-field.ts | 10 ++++++++-- .../dialog-automation-save.ts | 2 ++ src/panels/config/category/ha-category-picker.ts | 4 ++++ .../dialog-device-registry-detail.ts | 1 + .../entities/entity-registry-settings-editor.ts | 2 ++ 9 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/components/ha-area-picker.ts b/src/components/ha-area-picker.ts index 6a779119b0..c911a93650 100644 --- a/src/components/ha-area-picker.ts +++ b/src/components/ha-area-picker.ts @@ -51,6 +51,9 @@ export class HaAreaPicker extends LitElement { @property({ type: Boolean, attribute: "no-add" }) public noAdd = false; + @property({ type: Boolean, attribute: "show-label" }) + public showLabel = false; + /** * Show only areas with entities from specific domains. * @type {Array} @@ -365,9 +368,17 @@ export class HaAreaPicker extends LitElement { protected render(): TemplateResult { const placeholder = this.placeholder ?? this.hass.localize("ui.components.area-picker.area"); - const valueRenderer = this._computeValueRenderer(this.hass.areas); + let showLabel = this.showLabel; + if (this.value) { + const area = this.hass.areas[this.value]; + if (area) { + const { floor } = getAreaContext(area, this.hass.floors); + showLabel = !floor && this.showLabel; + } + } + return html` ${this.placeholder}` + : nothing; return html` ${this.value ? this.valueRenderer - ? this.valueRenderer(this.value) - : html`${this.value}` + ? html`${placeholder}${this.valueRenderer(this.value)}` + : html`${placeholder}${this.value}` : html` ${this.placeholder} diff --git a/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts b/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts index 16851ecbf2..cd6137dea3 100644 --- a/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts +++ b/src/panels/config/automation/automation-save-dialog/dialog-automation-save.ts @@ -177,6 +177,7 @@ class DialogAutomationSave extends LitElement implements HassDialog { .hass=${this.hass} .scope=${this._params.domain} .value=${this._entryUpdates.category} + show-label @value-changed=${this._registryEntryChanged} >` : nothing} @@ -193,6 +194,7 @@ class DialogAutomationSave extends LitElement implements HassDialog { id="area" .hass=${this.hass} .value=${this._entryUpdates.area} + show-label @value-changed=${this._registryEntryChanged} >` : nothing} diff --git a/src/panels/config/category/ha-category-picker.ts b/src/panels/config/category/ha-category-picker.ts index d52d55173e..27f7732243 100644 --- a/src/panels/config/category/ha-category-picker.ts +++ b/src/panels/config/category/ha-category-picker.ts @@ -39,6 +39,9 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) { @property({ type: Boolean, attribute: "no-add" }) public noAdd = false; + @property({ type: Boolean, attribute: "show-label" }) + public showLabel = false; + @property({ type: Boolean }) public disabled = false; @property({ type: Boolean }) public required = false; @@ -196,6 +199,7 @@ export class HaCategoryPicker extends SubscribeMixin(LitElement) { "ui.components.category-picker.no_categories" )} .placeholder=${placeholder} + .showLabel=${this.showLabel} .value=${this.value} .getItems=${this._getItems} .getAdditionalItems=${this._getAdditionalItems} diff --git a/src/panels/config/devices/device-registry-detail/dialog-device-registry-detail.ts b/src/panels/config/devices/device-registry-detail/dialog-device-registry-detail.ts index 4c350f46c0..7b14b44920 100644 --- a/src/panels/config/devices/device-registry-detail/dialog-device-registry-detail.ts +++ b/src/panels/config/devices/device-registry-detail/dialog-device-registry-detail.ts @@ -80,6 +80,7 @@ class DialogDeviceRegistryDetail extends LitElement { ` : ""} @@ -1012,6 +1013,7 @@ export class EntityRegistrySettingsEditor extends LitElement { ? html``