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
feat(presentation): name the keys of the toolbar buttons in their tooltips
Elian Doran065dc750513c
diff --git a/apps/client/src/widgets/collections/presentation/toolbar.tsx b/apps/client/src/widgets/collections/presentation/toolbar.tsxindex 75de49705f..ccb31ac2e1 100644--- a/apps/client/src/widgets/collections/presentation/toolbar.tsx+++ b/apps/client/src/widgets/collections/presentation/toolbar.tsx@@ -56,6 +56,7 @@ export default function PresentationToolbarActions({<ActionButtonicon="bx bx-check"text={t("presentation_view.finish-editing")}+ shortcut="Escape"onClick={onFinishEditing}/>)}@@ -80,6 +81,7 @@ export default function PresentationToolbarActions({<ActionButtonicon="bx bx-grid-horizontal"text={t("presentation_view.slide-overview")}+ shortcut="O"active={isOverviewActive}onClick={() => api?.toggleOverview()}/>@@ -87,6 +89,7 @@ export default function PresentationToolbarActions({<ActionButtonicon="bx bx-fullscreen"text={t("presentation_view.start-presentation")}+ shortcut="F"onClick={onStartPresentation}/></>diff --git a/apps/client/src/widgets/react/ActionButton.spec.tsx b/apps/client/src/widgets/react/ActionButton.spec.tsxindex 595108b543..560519c981 100644--- a/apps/client/src/widgets/react/ActionButton.spec.tsx+++ b/apps/client/src/widgets/react/ActionButton.spec.tsx@@ -80,4 +80,15 @@ describe("ActionButton", () => {expect(document.querySelector(".tooltip")).toBeNull();expect(onClick).toHaveBeenCalledOnce();});++ it("names a literal shortcut in its tooltip, for a key that is no configurable action", async () => {+ await act(async () => render(+ <ActionButton icon="bx bx-fullscreen" text="Start presentation" shortcut="F" />, container));+ const button = container.querySelector("button");+ act(() => {+ if (button) Tooltip.getInstance(button)?.show();+ });++ expect(document.querySelector(".tooltip-inner")?.textContent).toBe("Start presentation (F)");+ });});diff --git a/apps/client/src/widgets/react/ActionButton.tsx b/apps/client/src/widgets/react/ActionButton.tsxindex 391a8dc4d1..b2f021651b 100644--- a/apps/client/src/widgets/react/ActionButton.tsx+++ b/apps/client/src/widgets/react/ActionButton.tsx@@ -31,6 +31,8 @@ export interface ActionButtonProps extends Pick<*/noTooltipOnTouch?: boolean;triggerCommand?: CommandNames;+ /** A shortcut named in the tooltip as it is written, for a button whose key is no `triggerCommand` action. */+ shortcut?: string;noIconActionClass?: boolean;frame?: boolean;active?: boolean;@@ -39,9 +41,10 @@ export interface ActionButtonProps extends Pick<const cachedIsMobile = isMobile();-export default function ActionButton({ text, icon, className, triggerCommand, titlePosition, tooltipClass, tooltipHtml, noIconActionClass, noTooltipOnTouch, frame, active, disabled, ...restProps }: ActionButtonProps) {+export default function ActionButton({ text, icon, className, triggerCommand, shortcut, titlePosition, tooltipClass, tooltipHtml, noIconActionClass, noTooltipOnTouch, frame, active, disabled, ...restProps }: ActionButtonProps) {const buttonRef = useRef<HTMLButtonElement>(null);- const [ keyboardShortcut, setKeyboardShortcut ] = useState<string[]>();+ const [ actionShortcuts, setKeyboardShortcut ] = useState<string[]>();+ const keyboardShortcut = actionShortcuts ?? (shortcut ? [ shortcut ] : undefined);const triggerOwnCommand = useCommandTrigger(triggerCommand);const title = keyboardShortcut?.length