From 3a5bff8810e8aa723b4a9b1de3cfb8393a453022 Mon Sep 17 00:00:00 2001 From: Sli Date: Wed, 14 May 2025 13:37:36 +0200 Subject: [PATCH] Fix tooltip not appearing/disapearing when attribute is removed --- com/static/bundled/com/components/ics-calendar-index.ts | 2 -- core/static/bundled/core/tooltips-index.ts | 7 +++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/com/static/bundled/com/components/ics-calendar-index.ts b/com/static/bundled/com/components/ics-calendar-index.ts index 6816bace..6347cc22 100644 --- a/com/static/bundled/com/components/ics-calendar-index.ts +++ b/com/static/bundled/com/components/ics-calendar-index.ts @@ -327,7 +327,6 @@ export class IcsCalendar extends inheritHtmlElement("div") { button.classList.remove("text-copied"); } button.setAttribute("tooltip", gettext("Link copied")); - button.dispatchEvent(new Event("mouseover", { bubbles: true })); navigator.clipboard.writeText( new URL( await makeUrl(calendarCalendarInternal), @@ -339,7 +338,6 @@ export class IcsCalendar extends inheritHtmlElement("div") { button.classList.remove("text-copied"); button.classList.add("text-copied"); button.classList.remove("text-copy"); - button.dispatchEvent(new Event("mouseout", { bubbles: true })); button.removeAttribute("tooltip"); }, 1500); }, diff --git a/core/static/bundled/core/tooltips-index.ts b/core/static/bundled/core/tooltips-index.ts index eb0a201a..0b68a385 100644 --- a/core/static/bundled/core/tooltips-index.ts +++ b/core/static/bundled/core/tooltips-index.ts @@ -136,6 +136,13 @@ new MutationObserver((mutations: MutationRecord[]) => { if (target.hasAttribute("tooltip")) { target.addEventListener("mouseover", tooltipMouseover); target.addEventListener("mouseout", tooltipMouseout); + if (target.matches(":hover")) { + target.dispatchEvent(new Event("mouseover", { bubbles: true })); + } + } else if (tooltips.has(target)) { + // Remove corresponding tooltip + tooltips.get(target).remove(); + tooltips.delete(target); } } }).observe(document.body, {