Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
karwosts committed Dec 28, 2023
1 parent 4e62bb4 commit e6f7a92
Showing 1 changed file with 30 additions and 22 deletions.
52 changes: 30 additions & 22 deletions src/panels/lovelace/cards/hui-tile-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -359,15 +378,6 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
: undefined;
const badge = computeTileBadge(stateObj, this.hass);

const hasCardAction =
!this._config.tap_action ||
hasAction(this._config.tap_action) ||
hasAction(this._config.hold_action) ||
hasAction(this._config.double_tap_action);

const hasIconAction =
!this._config.icon_tap_action || hasAction(this._config.icon_tap_action);

return html`
<ha-card style=${styleMap(style)} class=${classMap({ active })}>
<div
Expand All @@ -377,18 +387,16 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
hasHold: hasAction(this._config!.hold_action),
hasDoubleClick: hasAction(this._config!.double_tap_action),
})}
role=${hasCardAction ? "button" : ""}
tabindex=${hasCardAction ? "0" : undefined}
role=${this.hasCardAction ? "button" : ""}
tabindex=${this.hasCardAction ? "0" : undefined}
aria-labelledby="info"
@mousedown=${hasCardAction ? this.handleRippleActivate : undefined}
@mouseup=${hasCardAction ? this.handleRippleDeactivate : undefined}
@mouseenter=${hasCardAction ? this.handleRippleMouseEnter : undefined}
@mouseleave=${hasCardAction ? this.handleRippleMouseLeave : undefined}
@touchstart=${hasCardAction ? this.handleRippleActivate : undefined}
@touchend=${hasCardAction ? this.handleRippleDeactivate : undefined}
@touchcancel=${hasCardAction
? this.handleRippleDeactivate
: undefined}
@mousedown=${this.handleRippleActivate}
@mouseup=${this.handleRippleDeactivate}
@mouseenter=${this.handleRippleMouseEnter}
@mouseleave=${this.handleRippleMouseLeave}
@touchstart=${this.handleRippleActivate}
@touchend=${this.handleRippleDeactivate}
@touchcancel=${this.handleRippleDeactivate}
>
${this._shouldRenderRipple
? html`<mwc-ripple></mwc-ripple>`
Expand All @@ -397,8 +405,8 @@ export class HuiTileCard extends LitElement implements LovelaceCard {
<div class="content ${classMap(contentClasses)}">
<div
class="icon-container"
role=${hasIconAction ? "button" : ""}
tabindex=${hasIconAction ? "0" : undefined}
role=${this.hasIconAction ? "button" : ""}
tabindex=${this.hasIconAction ? "0" : undefined}
@action=${this._handleIconAction}
.actionHandler=${actionHandler()}
>
Expand Down

0 comments on commit e6f7a92

Please sign in to comment.