Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(menu): keep tiles from repeating their title in a tooltip
Elian Doranaa5d9a6718b1
diff --git a/apps/client/src/widgets/react/Menu.spec.tsx b/apps/client/src/widgets/react/Menu.spec.tsxindex 22cfb30434..17ac3309b5 100644--- a/apps/client/src/widgets/react/Menu.spec.tsx+++ b/apps/client/src/widgets/react/Menu.spec.tsx@@ -513,7 +513,7 @@ describe("Menu with an action row", () => {it("names or describes each action in its tooltip, with the shortcut on line 1", async () => {const { menu } = renderMenu();- const [ cut, , remove ] = menu.querySelectorAll<HTMLElement>(".tn-menu-action");+ const [ cut, copy, remove ] = menu.querySelectorAll<HTMLElement>(".tn-menu-action");const tooltipText = (button: HTMLElement | undefined) => {const tooltip = button && Tooltip.getInstance(button);if (!tooltip) return undefined;@@ -530,6 +530,10 @@ describe("Menu with an action row", () => {const deleteKey = joinShortcut(formatShortcut("CommandOrControl+D"));await vi.waitFor(() =>expect(tooltipText(remove)).toBe(`Delete (${deleteKey})\nAsks first`));++ // Without a shortcut or a tooltip of its own, a tooltip would repeat the title under it.+ if (!copy) throw new Error("expected the Copy action to render");+ expect(Tooltip.getInstance(copy)).toBeNull();});it("gives the actions no tooltip on a phone, which has no pointer to hover with", async () => {diff --git a/apps/client/src/widgets/react/Menu.tsx b/apps/client/src/widgets/react/Menu.tsxindex 7f371cd05e..223eeeb86b 100644--- a/apps/client/src/widgets/react/Menu.tsx+++ b/apps/client/src/widgets/react/Menu.tsx@@ -626,7 +626,7 @@ function MenuAction<T>({ item, onSelect }: { item: MenuCommandItem<T>, onSelect:return (<MenuTileicon={item.uiIcon} iconBadge={item.uiIconBadge} title={item.title}- tooltip={item.tooltip ?? textOf(item.title)} keyboardShortcut={item.keyboardShortcut}+ tooltip={item.tooltip} keyboardShortcut={item.keyboardShortcut}disabled={item.enabled === false} onSelect={(e) => onSelect?.(item, e)}/>);@@ -641,8 +641,8 @@ interface MenuTileProps {iconBadge?: string;/** The title as HTML, as for a row's. */title: string;- /** The full title, which a narrow tile can cut short. */- tooltip: string;+ /** What the tooltip shows in place of the title, such as a word of explanation. */+ tooltip?: string;keyboardShortcut?: MenuCommandItem<unknown>["keyboardShortcut"];disabled?: boolean;/** Makes the tile one that is checked or not, which a menu tells assistive technology. */@@ -659,10 +659,12 @@ export function MenuTile({ icon, iconSvg, iconBadge, title, tooltip, keyboardShoconst level = useContext(MenuLevelContext);const id = useUniqueName("menu-row");const buttonRef = useRef<HTMLButtonElement | null>(null);- // 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.+ // The explanation or the shortcut a row would show, with the title only alongside a shortcut,+ // since the tile shows its title already. 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 ? "" : tooltip,+ const tooltipText = tooltip ?? (keyboardShortcut ? textOf(title) : "");+ useStaticTooltipWithKeyboardShortcut(buttonRef, mobile ? "" : tooltipText,mobile ? undefined : keyboardShortcut, ACTION_TOOLTIP);return (diff --git a/apps/client/src/widgets/type_widgets/text/toolbar_group_menu.tsx b/apps/client/src/widgets/type_widgets/text/toolbar_group_menu.tsxindex 479aa42468..887b54804a 100644--- a/apps/client/src/widgets/type_widgets/text/toolbar_group_menu.tsx+++ b/apps/client/src/widgets/type_widgets/text/toolbar_group_menu.tsx@@ -155,7 +155,7 @@ function MenuTileGroups({ items }: { items: ToolbarGroupMenuItem[] }) {): (<MenuTile- key={tileIndex} icon={iconClass} iconSvg={icon} title={escapeHtml(label)} tooltip={label}+ key={tileIndex} icon={iconClass} iconSvg={icon} title={escapeHtml(label)}disabled={!isEnabled} checked={isOn} onSelect={() => run?.()}/>)