Skip to content

Code maintenance/69596 improve static hover cards by using templates#21313

Merged
EinLama merged 11 commits intodevfrom
code-maintenance/69596-improve-static-hover-cards-by-using-templates
Mar 26, 2026
Merged

Code maintenance/69596 improve static hover cards by using templates#21313
EinLama merged 11 commits intodevfrom
code-maintenance/69596-improve-static-hover-cards-by-using-templates

Conversation

@EinLama
Copy link
Copy Markdown
Contributor

@EinLama EinLama commented Dec 2, 2025

Ticket

https://community.openproject.org/wp/69596

Refactors hover cards to make use of HTML template elements. This conveys the correct semantic meaning, since an existing DOM element is copied and rendered in a different location -> exactly what a template should do.

This elegant change additionally allowed us to streamline the behavior of the HoverCardTriggerController for both async and sync hover cards.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@EinLama EinLama changed the base branch from dev to release/17.0 December 2, 2025 16:16
@EinLama EinLama force-pushed the code-maintenance/69596-improve-static-hover-cards-by-using-templates branch 2 times, most recently from ea638c1 to 7a6f98e Compare December 9, 2025 08:34
@EinLama EinLama changed the base branch from release/17.0 to dev December 12, 2025 15:52
@EinLama EinLama marked this pull request as ready for review December 12, 2025 16:23
@myabc myabc requested a review from Copilot December 12, 2025 21:31
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors static hover cards to use semantic HTML <template> elements instead of hidden DOM containers. The change improves code semantics (templates are designed for content that should be instantiated elsewhere), eliminates the need for custom CSS hiding logic, and streamlines the HoverCardTriggerController to handle both asynchronous (Turbo Frame) and synchronous (template-based) hover cards uniformly.

Key Changes:

  • Replaced hidden DOM element pattern with <template> elements for static hover card content
  • Removed the op-hover-card--hidden-container CSS class (no longer needed since templates are inherently hidden)
  • Simplified controller logic by using template.content.cloneNode() instead of element cloning with ID removal

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
lookbook/docs/components/hover-cards.md.erb Updated documentation to reflect the new template-based pattern, including corrected examples and clarified behavior around ID usage
frontend/src/stimulus/controllers/hover-card-trigger.controller.ts Refactored to expect HTMLTemplateElement instead of HTMLElement, using template content cloning for cleaner instantiation
frontend/src/global_styles/content/_hover_cards.sass Removed obsolete op-hover-card--hidden-container CSS class definition
app/components/portfolios/details_component.html.erb Migrated from hidden div container to <template> element, moving ID from inner content to template itself
app/components/portfolios/details_component.sass Added width constraint for portfolio hover cards using :has() selector

Copy link
Copy Markdown
Contributor

@toy toy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small points primarily about using elements except template.

Not related to this PR, but I'm also wondering about animation, if it is beneficial overall (maybe more when loading remote content), if it can be faster (subjectively .25s feels like a slow appearance, while .1s as just not popping it right away) and, why no animation when hiding the popover (animating popovers can be interesting)?

@EinLama EinLama force-pushed the code-maintenance/69596-improve-static-hover-cards-by-using-templates branch from 0d2ce12 to 7f33281 Compare February 23, 2026 11:49
Copy link
Copy Markdown
Contributor Author

@EinLama EinLama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They there @toy

Thank you for the review. It took a long while, but I managed to finally get back to this PR and address all of your feedback 🎉

In the meantime, two new template hover cards were added for project attributes, I updated them accordingly.

@EinLama EinLama requested a review from toy February 23, 2026 12:18
@EinLama
Copy link
Copy Markdown
Contributor Author

EinLama commented Feb 23, 2026

Small points primarily about using elements except template.

Not related to this PR, but I'm also wondering about animation, if it is beneficial overall (maybe more when loading remote content), if it can be faster (subjectively .25s feels like a slow appearance, while .1s as just not popping it right away) and, why no animation when hiding the popover (animating popovers can be interesting)?

That is a valid point. The current solution was quickly added at the time and could be improved. I have created another code maintenance ticket for that.

Copy link
Copy Markdown
Contributor

@myabc myabc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a very quick code review. This looks very good!

@myabc myabc added the javascript Pull requests that update Javascript code label Mar 8, 2026
Copy link
Copy Markdown
Contributor

@toy toy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few nitpicks

@EinLama EinLama force-pushed the code-maintenance/69596-improve-static-hover-cards-by-using-templates branch from 78e3d31 to f07767c Compare March 26, 2026 08:56
@EinLama EinLama merged commit 0b5a8dd into dev Mar 26, 2026
20 of 21 checks passed
@EinLama EinLama deleted the code-maintenance/69596-improve-static-hover-cards-by-using-templates branch March 26, 2026 09:27
@github-actions github-actions bot locked and limited conversation to collaborators Mar 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

javascript Pull requests that update Javascript code

Development

Successfully merging this pull request may close these issues.

4 participants