Skip to content

Build your personal knowledge base with Trilium Notes

feat(search): show the search button's Enter hint again

Elian Dorane7bb9b9db93b
diff --git a/apps/client/src/widgets/react/Button.spec.tsx b/apps/client/src/widgets/react/Button.spec.tsx
index 9093b271d0..9087dafa17 100644
--- a/apps/client/src/widgets/react/Button.spec.tsx
+++ b/apps/client/src/widgets/react/Button.spec.tsx
@@ -76,4 +76,15 @@ describe("SplitButton", () => {
expect([ ...host.querySelectorAll<HTMLButtonElement>(".btn-group button") ]
.every((button) => button.classList.contains("btn-micro"))).toBe(true);
});
+
+ it("shows the main action's shortcut on its half", () => {
+ render((
+ <SplitButton text="Search" keyboardShortcut="Enter">
+ <FormListItem onClick={() => {}}>Search and execute</FormListItem>
+ </SplitButton>
+ ), host);
+
+ const [ main ] = host.querySelectorAll(".btn-group button");
+ expect(main?.querySelector("kbd")).not.toBeNull();
+ });
});
diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx
index 3e2933728f..bd3478cdfb 100644
--- a/apps/client/src/widgets/react/Button.tsx
+++ b/apps/client/src/widgets/react/Button.tsx
@@ -130,24 +130,27 @@ export function ButtonGroup({ size, className, children }: { size?: "sm" | "lg";
}
/** A button with the related actions in a menu beside it. */
-export function SplitButton({ text, icon, kind = "secondary", size = "normal", children, ...restProps }: {
+export function SplitButton({ text, icon, kind = "secondary", size = "normal", keyboardShortcut, children, ...restProps }: {
text: string;
/** The icon's full class, as `"bx bx-search"`. */
icon?: string;
kind?: "primary" | "secondary";
size?: "normal" | "small" | "micro";
title?: string;
+ /** The keys that run the main action, shown after its label as a button shows them. */
+ keyboardShortcut?: string;
/** Click handler for the main button component (not the split). */
onClick?: () => void;
/** The menu's rows: `FormListItem`s and the other `FormList` rows. */
children: ComponentChildren;
}) {
const look = `btn-${kind}${size === "small" ? " btn-sm" : size === "micro" ? " btn-micro" : ""}`;
+ const shortcutElements = !keyboardShortcut || cachedIsMobile ? null : renderShortcutKbds(keyboardShortcut);
return (
<ButtonGroup className="tn-split-button" size={size === "small" ? "sm" : undefined}>
<button type="button" class={`btn ${look}`} {...restProps}>
{icon && <Icon icon={icon} />}
- {text}
+ {text} {shortcutElements}
</button>
<Dropdown
buttonClassName={`${look} dropdown-toggle-split`}
diff --git a/apps/client/src/widgets/search/SearchDefinition.tsx b/apps/client/src/widgets/search/SearchDefinition.tsx
index 6fc6120f56..adbb78d269 100644
--- a/apps/client/src/widgets/search/SearchDefinition.tsx
+++ b/apps/client/src/widgets/search/SearchDefinition.tsx
@@ -142,6 +142,7 @@ function SearchButtonBar({ note, refreshResults, savePendingOptions }: {
<SplitButton
text={t("search_definition.search_button")} icon="bx bx-search"
size="micro"
+ keyboardShortcut="Enter"
onClick={refreshResults}
>
<FormListItem icon="bx bxs-zap" onClick={searchAndExecuteActions}>{t("search_definition.search_execute")}</FormListItem>