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
client/collections/board: fix an issue
Adorian Dorana3ca3c31119f
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 3854860aa2..999a53863f 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -245,10 +245,15 @@ export default function Column({// Focus reaching a column closes whichever one was open, and opens nothing: a collapsed column// is walked onto without being disturbed, and is opened by a click or by Space instead.const handleFocusIn = useCallback(() => {- if (!isActive) {- setActiveColumn(undefined);+ if (isActive) {+ return;}- }, [ isActive, setActiveColumn ]);++ // While the whole board is peeked, focus arriving settles the peek on this column rather+ // than closing every column: the reader has just gone to work in this one, and a press on+ // one of its cards is focus arriving before it is a click.+ setActiveColumn(isPeeked ? column : undefined);+ }, [ column, isActive, isPeeked, setActiveColumn ]);const openMenu = useCallback((e: ContextMenuEvent) => {openColumnContextMenu(api, e, {diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 6f8e69df81..f60a99c8aa 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -508,6 +508,45 @@ describe("Collapsed board columns", () => {show.mockRestore();});+ /**+ * A press on a card is focus arriving before it is a click, and while the whole board is peeked+ * every column reads as inactive. The column pressed in keeps its peek; the rest give theirs up.+ */+ it("settles a board-wide peek on the column pressed in", async () => {+ const { mountPoint } = await setup({ keepCollapsed: true });+ const board = mountPoint.querySelector<HTMLElement>(".board-view-container");+ const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});++ board?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));+ const expand = (show.mock.calls.at(-1)?.[0].items ?? []).find(item =>+ item && "uiIcon" in item && item.uiIcon === "bx bx-expand-alt");+ if (!expand || !("handler" in expand)) throw new Error("expected an expand entry");++ await act(async () => {+ expand.handler?.(expand, {} as never);+ await flush();+ });+ expect(isCollapsed(mountPoint, 0)).toBe(false);++ // Focus landing on one of its cards, which is what a press on a card does first.+ await act(async () => {+ columnAt(mountPoint, 0).querySelector(".board-note")+ ?.dispatchEvent(new Event("focusin", { bubbles: true }));+ await flush();+ });+ expect(isCollapsed(mountPoint, 0)).toBe(false);++ // And the peek is this column's alone: focus reaching another one closes it as usual.+ await act(async () => {+ columnAt(mountPoint, 1).querySelector("h3")+ ?.dispatchEvent(new Event("focusin", { bubbles: true }));+ await flush();+ });+ expect(isCollapsed(mountPoint, 0)).toBe(true);++ show.mockRestore();+ });+/*** The board's own menu offers what the board is as well as what it does: an editor for a new* column, and the two settings that decide which columns and cards it draws at all.