Skip to content

Build your personal knowledge base with Trilium Notes

fix(react): duplicate tooltips on focus vs hover

Elian Doranb99d4532dfc7
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 77119ce185..3646113cd3 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -633,6 +633,8 @@ export function useTooltip(elRef: RefObject<HTMLElement>, config: Partial<Toolti
return { showTooltip, hideTooltip };
}
+let tooltips = new Set<Tooltip>();
+
/**
* Similar to {@link useTooltip}, but doesn't expose methods to imperatively hide or show the tooltip.
*
@@ -645,7 +647,17 @@ export function useStaticTooltip(elRef: RefObject<Element>, config?: Partial<Too
if (!elRef?.current || !hasTooltip) return;
const tooltip = Tooltip.getOrCreateInstance(elRef.current, config);
+ elRef.current.addEventListener("show.bs.tooltip", () => {
+ // Hide all the other tooltips.
+ for (const otherTooltip of tooltips) {
+ if (otherTooltip === tooltip) continue;
+ otherTooltip.hide();
+ }
+ });
+ tooltips.add(tooltip);
+
return () => {
+ tooltips.delete(tooltip);
tooltip.dispose();
// workaround for https://github.com/twbs/bootstrap/issues/37474
(tooltip as any)._activeTrigger = {};