Skip to content

Commit

Permalink
Merge pull request #23 from EladBezalel/defaultOpen-toggeled
Browse files Browse the repository at this point in the history
feat: add defaultOpen option to open if there are active entities
  • Loading branch information
RossMcMillan92 authored Apr 23, 2022
2 parents 46a3392 + 6168e04 commit 6aa8a20
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Big thanks to [ofekashery, the author of vertical-stack-in-card](https://github.
| ---------- | ------- | ------------ | ----------------------------------------- |
| type | string | | `custom:collapsable-cards` |
| cards | list | | List of cards |
| defaultOpen | string | false | Whether the cards should be visible by default. Can also be set to `desktop-only` to be open by default on desktop and collapsed by default on mobile. |
| defaultOpen | string | false | Whether the cards should be visible by default. Can also be set to `desktop-only` to be open by default on desktop and collapsed by default on mobile. Or `contain-toggled` to open only if there are active entities |
| title | string | "Toggle" | Dropdown title |
| buttonStyle| string | "" | CSS overrides for the dropdown toggle button |

Expand Down
8 changes: 8 additions & 0 deletions collapsable-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ class VerticalStackInCard extends HTMLElement {
const styleTag = document.createElement('style')
styleTag.innerHTML = this.getStyles()
card.appendChild(styleTag);

if (
config.defaultOpen === 'contain-toggled' &&
config.cards.filter((c) => this._hass.states[c.entity]?.state === "on")
.length > 0
) {
toggleButton.click();
}
}

createToggleButton() {
Expand Down

0 comments on commit 6aa8a20

Please sign in to comment.