From 22929672a069db25a0a94f230c8c9f57ac0afdd7 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Wed, 3 Jan 2024 05:58:59 -0800 Subject: [PATCH] Remove tile pointer/ripple/index when it has no action (#19137) * Remove tile pointer/ripple/index when it has no action * update * Apply suggestions from code review Co-authored-by: Paul Bottein --------- Co-authored-by: Paul Bottein --- src/panels/lovelace/cards/hui-tile-card.ts | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/panels/lovelace/cards/hui-tile-card.ts b/src/panels/lovelace/cards/hui-tile-card.ts index 1c06426d1acb..b3470aeed569 100644 --- a/src/panels/lovelace/cards/hui-tile-card.ts +++ b/src/panels/lovelace/cards/hui-tile-card.ts @@ -287,21 +287,40 @@ export class HuiTileCard extends LitElement implements LovelaceCard { @eventOptions({ passive: true }) private handleRippleActivate(evt?: Event) { + if (!this.hasCardAction) return; this._rippleHandlers.startPress(evt); } private handleRippleDeactivate() { + if (!this.hasCardAction) return; this._rippleHandlers.endPress(); } private handleRippleMouseEnter() { + if (!this.hasCardAction) return; this._rippleHandlers.startHover(); } private handleRippleMouseLeave() { + if (!this.hasCardAction) return; this._rippleHandlers.endHover(); } + get hasCardAction() { + return ( + !this._config?.tap_action || + hasAction(this._config?.tap_action) || + hasAction(this._config?.hold_action) || + hasAction(this._config?.double_tap_action) + ); + } + + get hasIconAction() { + return ( + !this._config?.icon_tap_action || hasAction(this._config?.icon_tap_action) + ); + } + protected render() { if (!this._config || !this.hass) { return nothing; @@ -368,8 +387,8 @@ export class HuiTileCard extends LitElement implements LovelaceCard { hasHold: hasAction(this._config!.hold_action), hasDoubleClick: hasAction(this._config!.double_tap_action), })} - role="button" - tabindex="0" + role=${ifDefined(this.hasCardAction ? "button" : undefined)} + tabindex=${ifDefined(this.hasCardAction ? "0" : undefined)} aria-labelledby="info" @mousedown=${this.handleRippleActivate} @mouseup=${this.handleRippleDeactivate} @@ -386,8 +405,8 @@ export class HuiTileCard extends LitElement implements LovelaceCard {