Skip to content

Commit d01ef37

Browse files
dcapslockRomRider
andauthored
fix: Embedded light card handle issue (#989)
Fixes #427 Fixes #901 though Honeycomb menu should use capture event is their case. It could be that to prevent any unknown breaking change that a config option is used, but I could not think of a good name for it! --------- Co-authored-by: Jérôme Wiedemann <[email protected]>
1 parent 2c17386 commit d01ef37

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/button-card.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,12 @@ class ButtonCard extends LitElement {
918918
<div
919919
id=${key}
920920
@action=${this._stopPropagation}
921-
@click=${this._stopPropagation}
922-
@touchstart=${this._stopPropagation}
923-
@mousedown=${this._stopPropagation}
924-
@mouseup=${this._stopPropagation}
925-
@touchend=${this._stopPropagation}
926-
@touchcancel=${this._stopPropagation}
921+
@click=${this._sendToParent}
922+
@touchstart=${this._sendToParent}
923+
@mousedown=${this._sendToParent}
924+
@mouseup=${this._sendToParent}
925+
@touchend=${this._sendToParent}
926+
@touchcancel=${this._sendToParent}
927927
style=${styleMap(customStyle)}
928928
>
929929
${thing}
@@ -1526,4 +1526,10 @@ class ButtonCard extends LitElement {
15261526
private _stopPropagation(ev: Event): void {
15271527
ev.stopPropagation();
15281528
}
1529+
1530+
private _sendToParent(ev: Event): void {
1531+
ev.stopPropagation();
1532+
const event = new CustomEvent(ev.type, ev);
1533+
this.parentElement?.dispatchEvent(event);
1534+
}
15291535
}

test/ui-lovelace.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,6 +1471,9 @@ views:
14711471
entity: switch.skylight
14721472
show_icon: false
14731473
name: '[[[ return `Main entity: ${entity.entity_id || "unknown entity"}`; ]]]'
1474+
label: Tap should toggle
1475+
tap_action:
1476+
action: toggle
14741477
styles:
14751478
grid:
14761479
- grid-template-areas: '"n" "nested"'
@@ -1482,7 +1485,13 @@ views:
14821485
type: 'custom:button-card'
14831486
name: '[[[[ return (entity?.entity_id || "4[ ]: main button entity not known"); ]]]]'
14841487
label: '[[[ return `3[ ]: ${(entity?.entity_id || "main button state not known")}`; ]]]'
1488+
show_state: true
1489+
state_display: Above should show "not known" <br/> below should show ¨switch.skylight".<br/>Tap should not trigger parent button action
14851490
show_label: true
1491+
show_icon: false
1492+
tap_action:
1493+
action: more-info
1494+
entity: switch.skylight
14861495

14871496
- type: custom:button-card
14881497
entity: switch.skylight

0 commit comments

Comments
 (0)