Skip to content

Commit 5ce0383

Browse files
committed
fix(tooltip): Sometimes tooltip flashes
1 parent 2f582a4 commit 5ce0383

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

apps/client/src/services/note_tooltip.ts

+15-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import appContext from "../components/app_context.js";
88
import type FNote from "../entities/fnote.js";
99
import { t } from "./i18n.js";
1010

11+
// Track all elements that open tooltips
12+
let openTooltipElements: JQuery<HTMLElement>[] = [];
13+
1114
function setupGlobalTooltip() {
1215
$(document).on("mouseenter", "a", mouseEnterHandler);
1316

@@ -23,7 +26,11 @@ function setupGlobalTooltip() {
2326
}
2427

2528
function dismissAllTooltips() {
26-
$(".note-tooltip").remove();
29+
openTooltipElements.forEach($el => {
30+
$el.tooltip("dispose");
31+
$el.removeAttr("aria-describedby");
32+
});
33+
openTooltipElements = [];
2734
}
2835

2936
function setupElementTooltip($el: JQuery<HTMLElement>) {
@@ -86,8 +93,8 @@ async function mouseEnterHandler(this: HTMLElement) {
8693
// we need to check if we're still hovering over the element
8794
// since the operation to get tooltip content was async, it is possible that
8895
// we now create tooltip which won't close because it won't receive mouseleave event
89-
if ($(this).filter(":hover").length > 0) {
90-
$(this).tooltip({
96+
if ($link.filter(":hover").length > 0) {
97+
$link.tooltip({
9198
container: "body",
9299
// https://github.com/zadam/trilium/issues/2794 https://github.com/zadam/trilium/issues/2988
93100
// with bottom this flickering happens a bit less
@@ -103,7 +110,9 @@ async function mouseEnterHandler(this: HTMLElement) {
103110
});
104111

105112
dismissAllTooltips();
106-
$(this).tooltip("show");
113+
$link.tooltip("show");
114+
115+
openTooltipElements.push($link);
107116

108117
// Dismiss the tooltip immediately if a link was clicked inside the tooltip.
109118
$(`.${tooltipClass} a`).on("click", (e) => {
@@ -115,7 +124,8 @@ async function mouseEnterHandler(this: HTMLElement) {
115124
// click on links within tooltip etc. without tooltip disappearing
116125
// - once the user moves the cursor away from both link and the tooltip, hide the tooltip
117126
const checkTooltip = () => {
118-
if (!$(this).filter(":hover").length && !$(`.${linkId}:hover`).length) {
127+
128+
if (!$link.filter(":hover").length && !$(`.${linkId}:hover`).length) {
119129
// cursor is neither over the link nor over the tooltip, user likely is not interested
120130
dismissAllTooltips();
121131
} else {

0 commit comments

Comments
 (0)