Skip to content

Build your personal knowledge base with Trilium Notes

client/shortcut hints: add a footer with instructions how to close the panel in keyboard mode

Adorian Doran75acb32dff1d
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 092cf890c3..dabe89c8e4 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1012,7 +1012,8 @@
}
},
"shortcut_hints": {
- "show_button": "Show shortcut hints"
+ "show_button": "Show shortcut hints",
+ "esc_hint": "to close"
},
"zpetne_odkazy": {
"backlink_one": "{{count}} Backlink",
diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css
index a1860b180c..d22885a77e 100644
--- a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css
+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.css
@@ -59,4 +59,10 @@
content: ",";
margin-inline-end: 8px;
}
+
+ .shortcut-hints-footer {
+ margin-top: 0.6rem;
+ color: var(--muted-text-color);
+ font-size: 0.8em;
+ }
}
diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.spec.tsx b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.spec.tsx
index d74b1927f5..d4d92df13b 100644
--- a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.spec.tsx
+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.spec.tsx
@@ -69,6 +69,12 @@ describe("ShortcutHintsPanel", () => {
expect(document.querySelector(".shortcut-hints-panel")).toBeNull();
});
+ it("shows the Esc footer only when opened by keyboard (no anchor)", () => {
+ const host = mountPanel();
+ request(host, SECTIONS);
+ expect(document.querySelector(".shortcut-hints-footer")).not.toBeNull();
+ });
+
it("does not open when there are no sections", () => {
const host = mountPanel();
request(host, []);
@@ -118,6 +124,8 @@ describe("ShortcutHintsPanel", () => {
// Anchored positioning uses top/bottom-auto instead of the corner's bottom offset.
expect(panel?.style.top).toBe("6px");
expect(panel?.style.bottom).toBe("auto");
+ // No Esc footer when opened via the button (mouse users click away).
+ expect(document.querySelector(".shortcut-hints-footer")).toBeNull();
// A mousedown on the anchor is left for its own toggle — the pane must not close.
act(() => { anchor.dispatchEvent(new MouseEvent("mousedown", { bubbles: true })); });
diff --git a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx
index 5e624e9571..c690399f33 100644
--- a/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx
+++ b/apps/client/src/widgets/shortcut_hints/shortcut_hints_panel.tsx
@@ -90,6 +90,12 @@ export default function ShortcutHintsPanel() {
return createPortal(
<div ref={panelRef} className="shortcut-hints-panel tn-shortcut-hints-kbd" style={style} onMouseEnter={clearTimer} onMouseLeave={startTimer}>
<ShortcutHintsSections sections={state.sections} />
+ {/* Keyboard users get the Esc reminder; mouse users (opened via the button) click away. */}
+ {!state.anchor && (
+ <div className="shortcut-hints-footer">
+ {renderShortcutKbds("Escape")} {t("shortcut_hints.esc_hint")}
+ </div>
+ )}
</div>,
document.body
);