Skip to content

Commit 9cc85bc

Browse files
piitayaMindFreezebramkragten
authored
Fix hold action for picture element card in Android app (home-assistant#26647)
Co-authored-by: Petar Petrov <[email protected]> Co-authored-by: Bram Kragten <[email protected]>
1 parent 4f4343d commit 9cc85bc

File tree

3 files changed

+85
-53
lines changed

3 files changed

+85
-53
lines changed

src/panels/lovelace/cards/hui-picture-entity-card.ts

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PropertyValues, TemplateResult } from "lit";
22
import { LitElement, css, html, nothing } from "lit";
33
import { customElement, property, state } from "lit/decorators";
4+
import { classMap } from "lit/directives/class-map";
45
import { ifDefined } from "lit/directives/if-defined";
56
import { applyThemesOnElement } from "../../../common/dom/apply_themes_on_element";
67
import { computeDomain } from "../../../common/entity/compute_domain";
@@ -161,33 +162,40 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
161162
this.layout === "grid" &&
162163
typeof this._config.grid_options?.rows === "number";
163164

165+
const hasTapAction =
166+
hasAction(this._config.tap_action) ||
167+
Boolean(!this._config.tap_action && this._config.entity);
168+
164169
return html`
165170
<ha-card>
166-
<hui-image
167-
.hass=${this.hass}
168-
.image=${image}
169-
.stateImage=${this._config.state_image}
170-
.stateFilter=${this._config.state_filter}
171-
.cameraImage=${domain === "camera"
172-
? this._config.entity
173-
: this._config.camera_image}
174-
.cameraView=${this._config.camera_view}
175-
.entity=${this._config.entity}
176-
.aspectRatio=${ignoreAspectRatio
177-
? undefined
178-
: this._config.aspect_ratio}
179-
.fitMode=${this._config.fit_mode}
171+
<div
172+
class="image-container ${classMap({
173+
clickable: hasTapAction,
174+
})}"
180175
@action=${this._handleAction}
181176
.actionHandler=${actionHandler({
182177
hasHold: hasAction(this._config!.hold_action),
183178
hasDoubleClick: hasAction(this._config!.double_tap_action),
184179
})}
185-
tabindex=${ifDefined(
186-
hasAction(this._config.tap_action) || this._config.entity
187-
? "0"
188-
: undefined
189-
)}
190-
></hui-image>
180+
tabindex=${ifDefined(hasTapAction ? "0" : undefined)}
181+
role=${ifDefined(hasTapAction ? "0" : undefined)}
182+
>
183+
<hui-image
184+
.hass=${this.hass}
185+
.image=${image}
186+
.stateImage=${this._config.state_image}
187+
.stateFilter=${this._config.state_filter}
188+
.cameraImage=${domain === "camera"
189+
? this._config.entity
190+
: this._config.camera_image}
191+
.cameraView=${this._config.camera_view}
192+
.entity=${this._config.entity}
193+
.aspectRatio=${ignoreAspectRatio
194+
? undefined
195+
: this._config.aspect_ratio}
196+
.fitMode=${this._config.fit_mode}
197+
></hui-image>
198+
</div>
191199
${footer}
192200
</ha-card>
193201
`;
@@ -202,8 +210,15 @@ class HuiPictureEntityCard extends LitElement implements LovelaceCard {
202210
box-sizing: border-box;
203211
}
204212
205-
hui-image {
213+
.image-container {
214+
height: 100%;
215+
}
216+
.image-container.clickable {
206217
cursor: pointer;
218+
}
219+
220+
hui-image {
221+
pointer-events: none;
207222
height: 100%;
208223
}
209224

src/panels/lovelace/cards/hui-picture-glance-card.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -219,33 +219,37 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
219219

220220
return html`
221221
<ha-card>
222-
<hui-image
223-
class=${classMap({
222+
<div
223+
class="image-container ${classMap({
224224
clickable:
225225
hasTapAction ||
226226
hasAction(this._config.hold_action) ||
227227
hasAction(this._config.double_tap_action),
228-
})}
228+
})}"
229229
@action=${this._handleAction}
230230
.actionHandler=${actionHandler({
231231
hasTap: hasTapAction,
232232
hasHold: hasAction(this._config.hold_action),
233233
hasDoubleClick: hasAction(this._config.double_tap_action),
234234
})}
235235
tabindex=${ifDefined(hasTapAction ? "0" : undefined)}
236+
role=${ifDefined(hasTapAction ? "button" : undefined)}
236237
.config=${this._config}
237-
.hass=${this.hass}
238-
.image=${image}
239-
.stateImage=${this._config.state_image}
240-
.stateFilter=${this._config.state_filter}
241-
.cameraImage=${this._config.camera_image}
242-
.cameraView=${this._config.camera_view}
243-
.entity=${this._config.entity}
244-
.fitMode=${this._config.fit_mode}
245-
.aspectRatio=${ignoreAspectRatio
246-
? undefined
247-
: this._config.aspect_ratio}
248-
></hui-image>
238+
>
239+
<hui-image
240+
.hass=${this.hass}
241+
.image=${image}
242+
.stateImage=${this._config.state_image}
243+
.stateFilter=${this._config.state_filter}
244+
.cameraImage=${this._config.camera_image}
245+
.cameraView=${this._config.camera_view}
246+
.entity=${this._config.entity}
247+
.fitMode=${this._config.fit_mode}
248+
.aspectRatio=${ignoreAspectRatio
249+
? undefined
250+
: this._config.aspect_ratio}
251+
></hui-image>
252+
</div>
249253
<div class="box">
250254
${this._config.title
251255
? html`<div class="title">${this._config.title}</div>`
@@ -342,12 +346,16 @@ class HuiPictureGlanceCard extends LitElement implements LovelaceCard {
342346
height: 100%;
343347
box-sizing: border-box;
344348
}
345-
hui-image {
349+
.image-container {
346350
height: 100%;
347351
}
348-
hui-image.clickable {
352+
.image-container.clickable {
349353
cursor: pointer;
350354
}
355+
hui-image {
356+
pointer-events: none;
357+
height: 100%;
358+
}
351359
.box {
352360
position: absolute;
353361
left: 0;

src/panels/lovelace/elements/hui-image-element.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,7 @@ export class HuiImageElement extends LitElement implements LovelaceElement {
5151
}
5252

5353
return html`
54-
<hui-image
55-
.hass=${this.hass}
56-
.entity=${this._config.entity}
57-
.image=${stateObj ? computeImageUrl(stateObj) : this._config.image}
58-
.stateImage=${this._config.state_image}
59-
.cameraImage=${this._config.camera_image}
60-
.cameraView=${this._config.camera_view}
61-
.filter=${this._config.filter}
62-
.stateFilter=${this._config.state_filter}
63-
.title=${computeTooltip(this.hass, this._config)}
64-
.aspectRatio=${this._config.aspect_ratio}
65-
.darkModeImage=${this._config.dark_mode_image}
66-
.darkModeFilter=${this._config.dark_mode_filter}
54+
<div
6755
@action=${this._handleAction}
6856
.actionHandler=${actionHandler({
6957
hasHold: hasAction(this._config!.hold_action),
@@ -72,7 +60,25 @@ export class HuiImageElement extends LitElement implements LovelaceElement {
7260
tabindex=${ifDefined(
7361
hasAction(this._config.tap_action) ? "0" : undefined
7462
)}
75-
></hui-image>
63+
role=${ifDefined(
64+
hasAction(this._config.tap_action) ? "button" : undefined
65+
)}
66+
>
67+
<hui-image
68+
.hass=${this.hass}
69+
.entity=${this._config.entity}
70+
.image=${stateObj ? computeImageUrl(stateObj) : this._config.image}
71+
.stateImage=${this._config.state_image}
72+
.cameraImage=${this._config.camera_image}
73+
.cameraView=${this._config.camera_view}
74+
.filter=${this._config.filter}
75+
.stateFilter=${this._config.state_filter}
76+
.title=${computeTooltip(this.hass, this._config)}
77+
.aspectRatio=${this._config.aspect_ratio}
78+
.darkModeImage=${this._config.dark_mode_image}
79+
.darkModeFilter=${this._config.dark_mode_filter}
80+
></hui-image>
81+
</div>
7682
`;
7783
}
7884

@@ -84,9 +90,12 @@ export class HuiImageElement extends LitElement implements LovelaceElement {
8490
}
8591
hui-image {
8692
-webkit-user-select: none !important;
93+
pointer-events: none;
8794
}
88-
hui-image:focus {
95+
div:focus {
8996
outline: none;
97+
}
98+
div:focus hui-image {
9099
background: var(--divider-color);
91100
border-radius: 100%;
92101
}

0 commit comments

Comments
 (0)