From d5e5fa24a84f00f0fd68bfb980396870a704887d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Holan?= Date: Sun, 6 Nov 2022 11:42:41 +0100 Subject: [PATCH] Enable contain-toggled for stack (#25) * Fix contain-toggled for stacks * Fixed missing token * Fix inArray * Fix travesing cards * Fix conditions * Fixed typo --- collapsable-cards.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/collapsable-cards.js b/collapsable-cards.js index 57873dd..d90bfcd 100644 --- a/collapsable-cards.js +++ b/collapsable-cards.js @@ -64,14 +64,17 @@ class VerticalStackInCard extends HTMLElement { styleTag.innerHTML = this.getStyles() card.appendChild(styleTag); - if ( - config.defaultOpen === 'contain-toggled' && - config.cards.filter((c) => this._hass.states[c.entity]?.state !== "off") - .length > 0 - ) { + if (config.defaultOpen === 'contain-toggled' && config.cards.filter((c) => this.checkActiveCard(c)).length > 0) { toggleButton.click(); } } + + checkActiveCard(card) { + const containers = ["grid", "vertical-stack", "horizontal-stack"]; + return containers.includes(card.type) + ? card.cards.filter((c) => this.checkActiveCard(c)).length > 0 + : this._hass.states[card.entity]?.state !== "off" + } createToggleButton() { const toggleButton = document.createElement('button');