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(icons): open the picker without closing the dialog it stands in
Elian Doran31378ef4e2f8
diff --git a/apps/client/src/test/setup.ts b/apps/client/src/test/setup.tsindex 0830312f5b..eb3236bdd9 100644--- a/apps/client/src/test/setup.ts+++ b/apps/client/src/test/setup.ts@@ -52,6 +52,11 @@ function mockServer() {return [];}+ // Asked for by the icon picker as it opens, to sort the icons a note already wears first.+ if (url === "other/icon-usage") {+ return { iconClassToCountMap: {} };+ }+if (url === "tree") {return {branches: [],diff --git a/apps/client/src/widgets/react/IconPicker.spec.tsx b/apps/client/src/widgets/react/IconPicker.spec.tsxindex 0c6bc9df96..e1153b2e99 100644--- a/apps/client/src/widgets/react/IconPicker.spec.tsx+++ b/apps/client/src/widgets/react/IconPicker.spec.tsx@@ -1,3 +1,4 @@+import { act } from "preact/test-utils";import { describe, expect, it, vi } from "vitest";// Hoisted: a module in the import chain reads the device once as it loads (see ActionButton), which@@ -10,6 +11,10 @@ vi.mock("../../services/utils", async (importOriginal) => ({isMobile: () => isMobileMock()}));+// Raising the picker's dialog for real would need Bootstrap; what is asked of it is the point here.+const openDialogMock = vi.hoisted(() => vi.fn(async (dialog: JQuery<HTMLElement>, _closeActDialog?: boolean) => dialog));+vi.mock("../../services/dialog", () => ({ openDialog: openDialogMock }));+import { renderInto } from "../../test/render";import { IconPickerButton } from "./IconPicker";@@ -43,4 +48,27 @@ describe("IconPickerButton", () => {// installed pack, which is far more work than a button on screen should be doing.expect(document.body.querySelector(".icon-picker")).toBeNull();});++ /**+ * The button heads a note, and a title row is often a dialog's own header — the geo map's marker+ * sheet, the quick editor. A picker that closed the active dialog closed the one it was rendered+ * inside, taking itself down with it and leaving the backdrop over an empty page.+ */+ it("opens the picker on a phone without closing the dialog it stands in", () => {+ // Opening builds the grid, which reads the installed packs off the page.+ glob.iconRegistry = { sources: [] };++ const mobile = renderButton(true);+ openDialogMock.mockClear();++ const button = mobile.querySelector<HTMLElement>(".note-icon-widget button.note-icon");+ expect(button).toBeTruthy();+ act(() => {+ button?.dispatchEvent(new MouseEvent("click", { bubbles: true }));+ });++ expect(openDialogMock).toHaveBeenCalledOnce();+ // The `closeActDialog` argument, which is what stands a dialog down to make room.+ expect(openDialogMock.mock.calls[0][1]).toBe(false);+ });});diff --git a/apps/client/src/widgets/react/IconPicker.tsx b/apps/client/src/widgets/react/IconPicker.tsxindex ea0823cd8c..d2daee66bb 100644--- a/apps/client/src/widgets/react/IconPicker.tsx+++ b/apps/client/src/widgets/react/IconPicker.tsx@@ -203,6 +203,7 @@ function IconPickerModalButton({ icon, title, className, disabled, onSelect, onRshow={modalShown} onHidden={() => setModalShown(false)}className="icon-switcher note-icon-widget"scrollable+ stackable>{/* As many icons as the screen has room for, rather than the twelve a menu isbuilt for (see the CSS, which gives the grid the rest of the screen). */}