Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/components/ha-area-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,11 @@ export class HaAreaPicker extends LitElement {

protected render(): TemplateResult {
const placeholder =
this.placeholder ?? this.hass.localize("ui.components.area-picker.area");
this.placeholder ??
this.hass.localize("ui.components.area-picker.placeholder");
const notFoundLabel = this.hass.localize(
"ui.components.area-picker.no_match"
);

const valueRenderer = this._computeValueRenderer(this.hass.areas);

Expand All @@ -367,9 +371,7 @@ export class HaAreaPicker extends LitElement {
.autofocus=${this.autofocus}
.label=${this.label}
.helper=${this.helper}
.notFoundLabel=${this.hass.localize(
"ui.components.area-picker.no_match"
)}
.notFoundLabel=${notFoundLabel}
.placeholder=${placeholder}
.value=${this.value}
.getItems=${this._getItems}
Expand Down
6 changes: 1 addition & 5 deletions src/components/ha-generic-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { RenderItemFunction } from "@lit-labs/virtualizer/virtualize";
import { mdiPlaylistPlus } from "@mdi/js";
import { css, html, LitElement, nothing, type CSSResultGroup } from "lit";
import { customElement, property, query, state } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { tinykeys } from "tinykeys";
import { fireEvent } from "../common/dom/fire_event";
import type { HomeAssistant } from "../types";
Expand Down Expand Up @@ -107,9 +106,6 @@ export class HaGenericPicker extends LitElement {

protected render() {
return html`
${this.label
? html`<label ?disabled=${this.disabled}>${this.label}</label>`
: nothing}
<div class="container">
<div id="picker">
<slot name="field">
Expand All @@ -130,7 +126,7 @@ export class HaGenericPicker extends LitElement {
type="button"
class=${this._opened ? "opened" : ""}
compact
aria-label=${ifDefined(this.label)}
.label=${this.label}
@click=${this.open}
@clear=${this._clear}
.placeholder=${this.placeholder}
Expand Down
48 changes: 43 additions & 5 deletions src/components/ha-picker-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type TemplateResult,
} from "lit";
import { customElement, property, query } from "lit/decorators";
import { ifDefined } from "lit/directives/if-defined";
import { fireEvent } from "../common/dom/fire_event";
import "./ha-combo-box-item";
import type { HaComboBoxItem } from "./ha-combo-box-item";
Expand All @@ -33,6 +34,8 @@ export class HaPickerField extends LitElement {

@property() public placeholder?: string;

@property() public label?: string;

@property({ attribute: "hide-clear-icon", type: Boolean })
public hideClearIcon = false;

Expand All @@ -51,15 +54,35 @@ export class HaPickerField extends LitElement {
!!this.value && !this.required && !this.disabled && !this.hideClearIcon;

return html`
<ha-combo-box-item .disabled=${this.disabled} type="button" compact>
<ha-combo-box-item
.disabled=${this.disabled}
type="button"
compact
aria-label=${ifDefined(this.label)}
>
${this.value
? this.valueRenderer
? this.valueRenderer(this.value)
: html`<slot name="headline">${this.value}</slot>`
: html`<span slot="headline">${this.value}</span>`
: html`
<span slot="headline" class="placeholder">
${this.placeholder}
</span>
${this.label
? html`
<span
slot="headline"
class="label ${this.placeholder
? "with-placeholder"
: ""}"
>${this.label}</span
>
`
: nothing}
${this.placeholder
? html`
<span slot="headline" class="placeholder">
${this.placeholder}
</span>
`
: nothing}
`}
${showClearIcon
? html`
Expand Down Expand Up @@ -152,9 +175,24 @@ export class HaPickerField extends LitElement {
width: 32px;
}

.label {
padding: 0 8px;
color: var(--secondary-text-color);
line-height: var(--ha-line-height-normal);
font-size: var(--ha-font-size-m);
white-space: nowrap;
}

.label.with-placeholder {
line-height: var(--ha-line-height-condensed);
font-size: var(--ha-font-size-xs);
}

.placeholder {
color: var(--secondary-text-color);
padding: 0 8px;
line-height: var(--ha-line-height-normal);
font-size: var(--ha-font-size-m);
}
`,
];
Expand Down
1 change: 1 addition & 0 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,7 @@
"add_new": "Add new area…",
"no_areas": "You don't have any areas",
"no_match": "No matching areas found",
"placeholder": "Select an area",
"unassigned_areas": "Unassigned areas",
"failed_create_area": "Failed to create area."
},
Expand Down
Loading