Skip to content

Build your personal knowledge base with Trilium Notes

fix(mobile): leave the tooltip off a row of actions on a phone

Elian Doran647b68f36ebd
diff --git a/apps/client/src/widgets/react/Menu.spec.tsx b/apps/client/src/widgets/react/Menu.spec.tsx
index 7ee95c446c..c820fbdff8 100644
--- a/apps/client/src/widgets/react/Menu.spec.tsx
+++ b/apps/client/src/widgets/react/Menu.spec.tsx
@@ -283,6 +283,7 @@ describe("Menu with an action row", () => {
afterEach(() => {
render(null, host);
window.glob.isRtl = false;
+ window.glob.device = "desktop";
});
function renderMenu() {
@@ -361,6 +362,17 @@ describe("Menu with an action row", () => {
expect(tooltipText(remove)).toBe("Delete, asking first");
});
+ it("gives the actions no tooltip on a phone, which has no pointer to hover with", async () => {
+ window.glob.device = "mobile";
+ const { menu } = renderMenu();
+ const [ cut, , remove ] = menu.querySelectorAll<HTMLElement>(".tn-menu-action");
+ if (!cut || !remove) throw new Error("expected the actions to render");
+
+ await new Promise((resolve) => setTimeout(resolve));
+ expect(Tooltip.getInstance(cut)).toBeNull();
+ expect(Tooltip.getInstance(remove)).toBeNull();
+ });
+
it("keeps Right and Left for the submenus on the other rows, mirrored right to left", async () => {
const { menu } = renderMenu();
diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsx
index e0f8e3e89f..f27f5b79df 100644
--- a/apps/client/src/widgets/react/Menu.tsx
+++ b/apps/client/src/widgets/react/Menu.tsx
@@ -571,8 +571,11 @@ function MenuAction<T>({ item, onSelect }: { item: MenuCommandItem<T>, onSelect:
const disabled = item.enabled === false;
const select = (e: MouseEvent | KeyboardEvent) => onSelect?.(item, e);
const buttonRef = useRef<HTMLButtonElement | null>(null);
- // The full title, which a narrow menu can cut short, and the shortcut a row would show.
- useStaticTooltipWithKeyboardShortcut(buttonRef, item.tooltip ?? textOf(item.title), item.keyboardShortcut, ACTION_TOOLTIP);
+ // The full title, which a narrow menu can cut short, and the shortcut a row would show. A phone
+ // has no pointer to hover with and no keyboard, so it gets neither; an empty title shows none.
+ const mobile = isMobile();
+ useStaticTooltipWithKeyboardShortcut(buttonRef, mobile ? "" : item.tooltip ?? textOf(item.title),
+ mobile ? undefined : item.keyboardShortcut, ACTION_TOOLTIP);
return (
<button