diff --git a/src/components/ha-target-picker.ts b/src/components/ha-target-picker.ts
index 114d95a887..d2eae714b4 100644
--- a/src/components/ha-target-picker.ts
+++ b/src/components/ha-target-picker.ts
@@ -87,166 +87,208 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
protected render() {
if (this.addOnTop) {
- return html` ${this._renderChips()} ${this._renderItems()} `;
+ return html` ${this._renderPicker()} ${this._renderItems()} `;
}
- return html` ${this._renderItems()} ${this._renderChips()} `;
+ return html` ${this._renderItems()} ${this._renderPicker()} `;
}
private _renderValueChips() {
- return html`
- ${this.value?.floor_id
- ? ensureArray(this.value.floor_id).map(
- (floor_id) => html`
-
- `
- )
- : nothing}
- ${this.value?.area_id
- ? ensureArray(this.value.area_id).map(
- (area_id) => html`
-
- `
- )
- : nothing}
- ${this.value?.device_id
- ? ensureArray(this.value.device_id).map(
- (device_id) => html`
-
- `
- )
- : nothing}
- ${this.value?.entity_id
- ? ensureArray(this.value.entity_id).map(
- (entity_id) => html`
-
- `
- )
- : nothing}
- ${this.value?.label_id
- ? ensureArray(this.value.label_id).map(
- (label_id) => html`
-
- `
- )
- : nothing}
-
`;
- }
+ const entityIds = this.value?.entity_id
+ ? ensureArray(this.value.entity_id)
+ : [];
+ const deviceIds = this.value?.device_id
+ ? ensureArray(this.value.device_id)
+ : [];
+ const areaIds = this.value?.area_id ? ensureArray(this.value.area_id) : [];
+ const floorIds = this.value?.floor_id
+ ? ensureArray(this.value.floor_id)
+ : [];
+ const labelIds = this.value?.label_id
+ ? ensureArray(this.value.label_id)
+ : [];
- private _renderValueGroups() {
- return html`
- ${this.value?.entity_id
- ? html`
-
-
- `
- : nothing}
- ${this.value?.device_id
- ? html`
-
-
- `
- : nothing}
- ${this.value?.floor_id || this.value?.area_id
- ? html`
-
-
- `
- : nothing}
- ${this.value?.label_id
- ? html`
-
-
- `
- : nothing}
-
`;
- }
-
- private _renderItems() {
if (
- !this.value?.floor_id &&
- !this.value?.area_id &&
- !this.value?.device_id &&
- !this.value?.entity_id &&
- !this.value?.label_id
+ !entityIds.length &&
+ !deviceIds.length &&
+ !areaIds.length &&
+ !floorIds.length &&
+ !labelIds.length
) {
return nothing;
}
+ return html`
+
+ ${floorIds.length
+ ? floorIds.map(
+ (floor_id) => html`
+
+ `
+ )
+ : nothing}
+ ${areaIds.length
+ ? areaIds.map(
+ (area_id) => html`
+
+ `
+ )
+ : nothing}
+ ${deviceIds.length
+ ? deviceIds.map(
+ (device_id) => html`
+
+ `
+ )
+ : nothing}
+ ${entityIds.length
+ ? entityIds.map(
+ (entity_id) => html`
+
+ `
+ )
+ : nothing}
+ ${labelIds.length
+ ? labelIds.map(
+ (label_id) => html`
+
+ `
+ )
+ : nothing}
+
+ `;
+ }
+
+ private _renderValueGroups() {
+ const entityIds = this.value?.entity_id
+ ? ensureArray(this.value.entity_id)
+ : [];
+ const deviceIds = this.value?.device_id
+ ? ensureArray(this.value.device_id)
+ : [];
+ const areaIds = this.value?.area_id ? ensureArray(this.value.area_id) : [];
+ const floorIds = this.value?.floor_id
+ ? ensureArray(this.value.floor_id)
+ : [];
+ const labelIds = this.value?.label_id
+ ? ensureArray(this.value?.label_id)
+ : [];
+
+ if (
+ !entityIds.length &&
+ !deviceIds.length &&
+ !areaIds.length &&
+ !floorIds.length &&
+ !labelIds.length
+ ) {
+ return nothing;
+ }
+
+ return html`
+
+ ${entityIds.length
+ ? html`
+
+
+ `
+ : nothing}
+ ${deviceIds.length
+ ? html`
+
+
+ `
+ : nothing}
+ ${floorIds.length || areaIds.length
+ ? html`
+
+
+ `
+ : nothing}
+ ${labelIds.length
+ ? html`
+
+
+ `
+ : nothing}
+
+ `;
+ }
+
+ private _renderItems() {
return html`
${this.compact ? this._renderValueChips() : this._renderValueGroups()}
`;
}
- private _renderChips() {
+ private _renderPicker() {
return html`
`;
@@ -148,6 +147,13 @@ export class HuiLogbookCardEditor
);
}
};
+
+ static styles = css`
+ ha-target-picker {
+ display: block;
+ margin-top: var(--ha-space-4);
+ }
+ `;
}
declare global {