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: make the SPACE key to expand/collapse the column, when a column header is focused
Adorian Doranc08dda0358d8
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 33c2639c36..6bae2dc89e 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -3544,6 +3544,7 @@"insert_item": "Insert card below / above","insert_column": "Insert column after / before","open_item": "Open card",+ "toggle_column": "Collapse / expand the column (on a column header)","rename": "Rename card or column","remove_item": "Remove card from the board","delete_item": "Delete the note",diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex e7137da45b..8bf1f50ea9 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -517,7 +517,16 @@ export default function Column({if (e.key === "F2" && !isCollapsed) {setColumnNameToEdit(column);}- }, [ column, isCollapsed ]);++ // The other half of the toggle: the board's keyboard answers Space on a strip, which also+ // has to step focus onto the cards the column then draws. Only on the heading itself, the+ // buttons it carries answering Space for themselves.+ if (e.key === " " && !isCollapsed && e.target === e.currentTarget) {+ e.preventDefault();+ e.stopPropagation();+ collapse();+ }+ }, [ collapse, column, isCollapsed ]);const overlayHost = useContext(BoardOverlayHostContext);/** Whether the heading holds the focus, which on mobile floats the column's rail. */@@ -685,8 +694,8 @@ export default function Column({ref={headerRef}className={`${isEditing ? "editing" : ""}`}// While collapsed the header is what opens the column, so it says so and answers- // for the keys a button answers for. Open, it is a heading again and Space does- // nothing, so neither is claimed.+ // for the keys a button answers for. Open, it is a heading again and claims+ // neither, `handleTitleKeyDown` taking the Space that collapses it.role={isCollapsed ? "button" : undefined}aria-expanded={isCollapsed ? false : undefined}onContextMenu={openMenu}diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsxindex 3936a3ffe3..bf944724a6 100644--- a/apps/client/src/widgets/collections/board/index.spec.tsx+++ b/apps/client/src/widgets/collections/board/index.spec.tsx@@ -737,6 +737,25 @@ describe("Collapsed board columns", () => {* The menu is opened from the column, so that column is the open one. Storing the flag alone* would change nothing on screen and leave the reader with no sign the entry did anything.*/+ it("collapses the column when Space is pressed on its heading", async () => {+ const { mountPoint } = await setup();+ const header = columnAt(mountPoint, 1).querySelector<HTMLElement>("h3");+ expect(header).not.toBeNull();+ header?.focus();++ await act(async () => {+ header?.dispatchEvent(new KeyboardEvent("keydown", { key: " ", bubbles: true }));+ await flush();+ });++ expect(isCollapsed(mountPoint, 1)).toBe(true);+ expect(saved.at(-1)?.columns?.[1]).toEqual({ value: "Done", collapsed: true });+ // The reader is left on the strip's header, which is what opens the column again.+ const strip = columnAt(mountPoint, 1).querySelector("h3");+ expect(document.activeElement).toBe(strip);+ expect(strip?.getAttribute("aria-expanded")).toBe("false");+ });+it("closes the column as soon as the menu entry collapses it", async () => {const { mountPoint } = await setup();const column = columnAt(mountPoint, 1);@@ -1258,6 +1277,7 @@ describe("Board column rename", () => {labelKey: "board_view.hints.insert_column"},{ keys: [ "Space" ], labelKey: "board_view.hints.open_item" },+ { keys: [ "Space" ], labelKey: "board_view.hints.toggle_column" },{ keys: [ "F2" ], labelKey: "board_view.hints.rename" },{ keys: [ "Delete" ], labelKey: "board_view.hints.remove_item" },{ keys: [ "Shift+Delete" ], labelKey: "board_view.hints.delete_item" },diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 8edcf4c193..7abac0db08 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -311,6 +311,7 @@ const BOARD_HINTS: ShortcutHintDefinition = [labelKey: "board_view.hints.insert_column"},{ keys: [ "Space" ], labelKey: "board_view.hints.open_item" },+ { keys: [ "Space" ], labelKey: "board_view.hints.toggle_column" },{ keys: [ "F2" ], labelKey: "board_view.hints.rename" },{ keys: [ "Delete" ], labelKey: "board_view.hints.remove_item" },{ keys: [ "Shift+Delete" ], labelKey: "board_view.hints.delete_item" },diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsxindex 1291e22336..a8f645ffcb 100644--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx@@ -503,11 +503,22 @@ describe("Board keyboard", () => {expect(focusedName(board)).toBe("Third");});- it("leaves Space and Enter alone on a column that is not collapsed", async () => {+ /** Drawn as a strip in `index.spec.tsx`, where the harness reads the write back. */+ it("collapses an open column with Space instead of walking on", async () => {const board = await renderBoard();focusHeader(board, 1);press(board, " ");+ await act(async () => { await flush(); });++ expect(saved.at(-1)?.columns?.find(col => col.value === "Doing")?.collapsed)+ .toBe(true);+ });++ it("leaves Enter alone on a column that is not collapsed", async () => {+ const board = await renderBoard();+ focusHeader(board, 1);+press(board, "Enter");expect(document.activeElement).toBe(columnAt(board, 1).querySelector("h3"));diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.tsindex efab3418a6..e93821931b 100644--- a/apps/client/src/widgets/collections/board/keyboard.ts+++ b/apps/client/src/widgets/collections/board/keyboard.ts@@ -288,7 +288,8 @@ export function useBoardKeyboard({return;}- // Both keys, the collapsed header answering for a button and being announced as one.+ // Both keys, the collapsed header answering for a button and being announced as one. An+ // open column is collapsed by the header itself, which draws the collapse it asked for.if ((e.key === " " || e.key === "Enter") && spot.kind === "header") {const column = columns[spot.column];if (!columnsOf(container)[spot.column]?.classList.contains("collapsed")) return;