From 9c3f77532c4258974dc5fef19ab03fbf652214a5 Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Tue, 8 Apr 2025 15:17:05 +0200 Subject: [PATCH] Make the full generic entity row clickable (#24968) * Make the full generic entity row clickable * Apply suggestions from code review Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com> --------- Co-authored-by: Wendelin <12148533+wendevlin@users.noreply.github.com> --- .../components/hui-generic-entity-row.ts | 191 +++++++++--------- 1 file changed, 98 insertions(+), 93 deletions(-) diff --git a/src/panels/lovelace/components/hui-generic-entity-row.ts b/src/panels/lovelace/components/hui-generic-entity-row.ts index 9011851555..441126240d 100644 --- a/src/panels/lovelace/components/hui-generic-entity-row.ts +++ b/src/panels/lovelace/components/hui-generic-entity-row.ts @@ -61,15 +61,8 @@ export class HuiGenericEntityRow extends LitElement { const name = this.config.name ?? computeStateName(stateObj); return html` - - ${!this.hideName - ? html`
- ${this.config.name || computeStateName(stateObj)} - ${hasSecondary - ? html` -
- ${this.secondaryText || - (this.config.secondary_info === "entity-id" - ? stateObj.entity_id - : this.config.secondary_info === "last-changed" - ? html` - - ` - : this.config.secondary_info === "last-updated" + > + + ${!this.hideName + ? html`
+ ${this.config.name || computeStateName(stateObj)} + ${hasSecondary + ? html` +
+ ${this.secondaryText || + (this.config.secondary_info === "entity-id" + ? stateObj.entity_id + : this.config.secondary_info === "last-changed" ? html` ` - : this.config.secondary_info === "last-triggered" - ? stateObj.attributes.last_triggered - ? html` - - ` - : this.hass.localize( - "ui.panel.lovelace.cards.entities.never_triggered" - ) - : this.config.secondary_info === "position" && - stateObj.attributes.current_position !== - undefined - ? `${this.hass.localize( - "ui.card.cover.position" - )}: ${stateObj.attributes.current_position}` - : this.config.secondary_info === - "tilt-position" && - stateObj.attributes.current_tilt_position !== + : this.config.secondary_info === "last-updated" + ? html` + + ` + : this.config.secondary_info === "last-triggered" + ? stateObj.attributes.last_triggered + ? html` + + ` + : this.hass.localize( + "ui.panel.lovelace.cards.entities.never_triggered" + ) + : this.config.secondary_info === "position" && + stateObj.attributes.current_position !== undefined ? `${this.hass.localize( - "ui.card.cover.tilt_position" - )}: ${ - stateObj.attributes.current_tilt_position - }` - : this.config.secondary_info === "brightness" && - stateObj.attributes.brightness - ? html`${Math.round( - (stateObj.attributes.brightness / 255) * - 100 - )} - %` - : "")} -
- ` - : ""} -
` - : nothing} - ${(this.catchInteraction ?? !DOMAINS_INPUT_ROW.includes(domain)) - ? html`
-
-
` - : html``} + "ui.card.cover.position" + )}: ${stateObj.attributes.current_position}` + : this.config.secondary_info === + "tilt-position" && + stateObj.attributes + .current_tilt_position !== undefined + ? `${this.hass.localize( + "ui.card.cover.tilt_position" + )}: ${ + stateObj.attributes.current_tilt_position + }` + : this.config.secondary_info === + "brightness" && + stateObj.attributes.brightness + ? html`${Math.round( + (stateObj.attributes.brightness / 255) * + 100 + )} + %` + : nothing)} +
+ ` + : nothing} +
` + : nothing} + ${(this.catchInteraction ?? !DOMAINS_INPUT_ROW.includes(domain)) + ? html`
+
+
` + : html``} + `; } @@ -194,6 +188,17 @@ export class HuiGenericEntityRow extends LitElement { align-items: center; flex-direction: row; } + .row { + display: flex; + align-items: center; + flex-direction: row; + width: 100%; + outline: none; + transition: background-color 180ms ease-in-out; + } + .row:focus-visible { + background-color: var(--primary-background-color); + } .info { padding-left: 16px; padding-right: 8px;