@@ -20,6 +20,7 @@ import {
20
20
ButtonCardEmbeddedCards ,
21
21
ButtonCardEmbeddedCardsConfig ,
22
22
ColorType ,
23
+ CustomFields ,
23
24
} from './types/types' ;
24
25
import { actionHandler } from './action-handler' ;
25
26
import {
@@ -868,38 +869,26 @@ class ButtonCard extends LitElement {
868
869
return result ;
869
870
}
870
871
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
+
871
883
private _isClickable ( state : HassEntity | undefined , configState : StateConfig | undefined ) : boolean {
872
- let clickable = true ;
873
884
const tap_action = this . _getTemplateOrValue ( state , this . _config ! . tap_action ! . action ) ;
874
885
const hold_action = this . _getTemplateOrValue ( state , this . _config ! . hold_action ! . action ) ;
875
886
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 ;
903
892
}
904
893
905
894
private _rotate ( configState : StateConfig | undefined ) : boolean {
0 commit comments