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(mobile/split): keep the sidebar button from switching the active split
Elian Doran713e10bcbf57
diff --git a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsx b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsxnew file mode 100644index 0000000000..69eb0a7f74--- /dev/null+++ b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.spec.tsx@@ -0,0 +1,32 @@+import { describe, expect, it, vi } from "vitest";++import { renderInto } from "../../test/render";++const { triggerCommand } = vi.hoisted(() => ({ triggerCommand: vi.fn() }));++vi.mock("../react/hooks", async (importOriginal) => ({+ ...(await importOriginal<typeof import("../react/hooks")>()),+ useNoteContext: () => ({+ noteContext: { isMainContext: () => true },+ parentComponent: { triggerCommand }+ }),+ useStaticTooltip: vi.fn()+}));++import ToggleSidebarButton from "./toggle_sidebar_button";++describe("ToggleSidebarButton", () => {+ it("opens the sidebar without activating the split it sits in", () => {+ const container = renderInto(<ToggleSidebarButton />);+ // `SplitNoteContainer` binds this on the `.note-split` the button renders inside.+ const activateSplit = vi.fn();+ container.addEventListener("click", activateSplit);++ const button = container.querySelector("button");+ expect(button).not.toBeNull();+ button?.click();++ expect(triggerCommand).toHaveBeenCalledWith("setActiveScreen", { screen: "tree" });+ expect(activateSplit).not.toHaveBeenCalled();+ });+});diff --git a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsxindex b87e8cb90e..395c049e86 100644--- a/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx+++ b/apps/client/src/widgets/mobile_widgets/toggle_sidebar_button.tsx@@ -11,6 +11,11 @@ export default function ToggleSidebarButton() {icon="bx bx-sidebar"text={t("note_tree.toggle-sidebar")}onClick={(e) => {+ // `SplitNoteContainer` activates the split a click lands in, so letting this one+ // bubble would focus the main split -- the one this button sits in -- every time+ // the sidebar is opened.+ e.stopPropagation();+// Remove focus to prevent tooltip showing on top of the sidebar.(e.currentTarget as HTMLButtonElement).blur();