Skip to content

Commit 56c3f44

Browse files
committed
fix: card would sometimes not be clickable
Fix #738, Fix #759
1 parent 121ae82 commit 56c3f44

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

src/button-card.ts

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
ButtonCardEmbeddedCards,
2121
ButtonCardEmbeddedCardsConfig,
2222
ColorType,
23+
CustomFields,
2324
} from './types/types';
2425
import { actionHandler } from './action-handler';
2526
import {
@@ -868,38 +869,26 @@ class ButtonCard extends LitElement {
868869
return result;
869870
}
870871

872+
private _hasChildCards(customFields: CustomFields | undefined): boolean {
873+
if (!customFields) return false;
874+
return Object.keys(customFields).some((key) => {
875+
const value = customFields![key];
876+
if ((value as CustomFieldCard)!.card) {
877+
return true;
878+
}
879+
return false;
880+
});
881+
}
882+
871883
private _isClickable(state: HassEntity | undefined, configState: StateConfig | undefined): boolean {
872-
let clickable = true;
873884
const tap_action = this._getTemplateOrValue(state, this._config!.tap_action!.action);
874885
const hold_action = this._getTemplateOrValue(state, this._config!.hold_action!.action);
875886
const double_tap_action = this._getTemplateOrValue(state, this._config!.double_tap_action!.action);
876-
let hasChildCards = false;
877-
if (this._config!.custom_fields) {
878-
hasChildCards = Object.keys(this._config!.custom_fields).some((key) => {
879-
const value = this._config!.custom_fields![key];
880-
if ((value as CustomFieldCard)!.card) {
881-
return true;
882-
}
883-
return false;
884-
});
885-
}
886-
if (!hasChildCards && configState) {
887-
if (configState.custom_fields) {
888-
return (hasChildCards = Object.keys(configState.custom_fields).some((key) => {
889-
const value = configState.custom_fields![key];
890-
if ((value as CustomFieldCard)!.card) {
891-
return true;
892-
}
893-
return false;
894-
}));
895-
}
896-
}
897-
if (tap_action != 'none' || hold_action != 'none' || double_tap_action != 'none' || hasChildCards) {
898-
clickable = true;
899-
} else {
900-
clickable = false;
901-
}
902-
return clickable;
887+
const hasChildCards =
888+
this._hasChildCards(this._config!.custom_fields) ||
889+
!!(configState && this._hasChildCards(configState.custom_fields));
890+
891+
return tap_action != 'none' || hold_action != 'none' || double_tap_action != 'none' || hasChildCards;
903892
}
904893

905894
private _rotate(configState: StateConfig | undefined): boolean {

0 commit comments

Comments
 (0)