Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure popup card is fully hidden when not editing. #747

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

j9brown
Copy link

@j9brown j9brown commented Sep 5, 2024

As of some recent version of Home Assistant (perhaps 2024.7) the popup-card is not completely hidden when not in editing mode and it interferes with the layout of section views.

On a related front, Home Assistant 2024.7 renamed "edit-mode" to "preview" although it preserved backwards compatibility (perhaps not completely accurately though). Refer to: home-assistant/frontend#21065

You might want to rename the edit-mode attribute to preview to match. I just did so in decluttering-card after tracking down the same visibility issue.

Moreover, I think this code is now unnecessary and can be removed altogether:

    if (this.parentElement.localName === "hui-card-preview") {
      this.editMode = true;
    }

The hui-card listens for this event to observe when its child's
hidden attribute changes then it hides itself.
@j9brown
Copy link
Author

j9brown commented Sep 7, 2024

Hmm, on further examination, this change doesn't quite work as intended for the browser-mod pop-ups in its current form because the parent hui-card removes the pop-up element from the DOM when it hides itself thereby causing the disconnectedCallback() to run and to unregister the more-info event handler from the window. Tricky.

Setting the pop-up card element's hidden attribute completely removes
it from the layout and prevents unsightly gaps in section views.
Unfortunately, that also disconnects the element from the document
so we can't use the connected callback to determine when to register
the event handlers.

To work around this issue, globally register the more-info event
handler on the window and search the Lovelace configuration for
the card definition so it doesn't matter whether the card is visible
and it can even be defined in any view of the same dashboard.
Follows a change in Home Assistant 2024.7.
@j9brown
Copy link
Author

j9brown commented Sep 7, 2024

Ok, I applied the same logic I used in decluttering-card to search for pop-up cards anywhere in the dashboard configuration regardless of whether they are hidden.

This change has the side-effect of expanding the scope of pop-up cards instead of being confined to usage within the same view they were defined. I think that should be fine most of the time but to improve backwards compatibility we could add a flag to govern how the card is resolved or define some new type of card with different semantics.

This change also opens up the possibility of defining pop-up cards that can be referenced by name from a fireDomEvent action instead of or in addition to being tied to more-info. It could be more convenient than declaring the cards at the call site in YAML. In principle the pop-up cards could also be parameterized similar to decluttering-card in future versions.

It seems to be more reliable this way. Without the delay the newly
opened pop-up would sometimes be dismissed immediately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant