Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: make the collapsed columns to permanently stay open after expanding, unless "Keep the column collapsed" option is active

Adorian Doran63a4ae057279
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 3893d31359..eac69cc246 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3413,6 +3413,8 @@
"edit-note-title": "Click to edit note title",
"rename-column": "Rename column",
"collapse-column": "Collapse column",
+ "keep-column-collapsed": "Keep the column collapsed",
+ "collapse-hint": "Double click to collapse",
"set-limit": "Set limit...",
"set-limit-ok": "Set limit",
"limit-capacity": "Warn for exceeding the column capacity",
diff --git a/apps/client/src/widgets/collections/board/api.spec.ts b/apps/client/src/widgets/collections/board/api.spec.ts
index 85a4ddfd8e..5a9735d960 100644
--- a/apps/client/src/widgets/collections/board/api.spec.ts
+++ b/apps/client/src/widgets/collections/board/api.spec.ts
@@ -1165,6 +1165,30 @@ describe("collapsing a column", () => {
expect(saved.at(-1)?.columns).toEqual([ { value: "To Do" }, { value: "Done" } ]);
});
+ /**
+ * Turning it on collapses the column as well, so the entry does something the reader can see
+ * rather than only deciding what the next open does.
+ */
+ it("collapses the column as it is set to stay collapsed", async () => {
+ const { api, saved } = createApi({ columns: [ { value: "To Do" } ] }, [ "To Do" ]);
+
+ expect(api.isColumnKeptCollapsed("To Do")).toBe(false);
+
+ await api.setColumnKeepCollapsed("To Do", true);
+ expect(saved.at(-1)?.columns)
+ .toEqual([ { value: "To Do", collapsed: true, keepCollapsed: true } ]);
+
+ // Turning it off on a strip leaves the column collapsed: opening it is what clears that.
+ await api.setColumnKeepCollapsed("To Do", false);
+ expect(saved.at(-1)?.columns).toEqual([ { value: "To Do", collapsed: true } ]);
+
+ // Turning it off on a column drawn open keeps it open, rather than letting the next
+ // column selected shut it again.
+ await api.setColumnKeepCollapsed("To Do", true);
+ await api.setColumnKeepCollapsed("To Do", false, true);
+ expect(saved.at(-1)?.columns).toEqual([ { value: "To Do" } ]);
+ });
+
it("leaves the column's other properties alone", async () => {
const { api, saved } = createApi(
{ columns: [ { value: "To Do", icon: "bx bx-star", limit: 3 } ] }, [ "To Do" ]);
diff --git a/apps/client/src/widgets/collections/board/api.ts b/apps/client/src/widgets/collections/board/api.ts
index 9f3818c57a..651e3dba56 100644
--- a/apps/client/src/widgets/collections/board/api.ts
+++ b/apps/client/src/widgets/collections/board/api.ts
@@ -537,6 +537,30 @@ export default class BoardApi {
this.updateColumn(column, { collapsed });
}
+ /** Whether a column collapses again once it has been opened. */
+ isColumnKeptCollapsed(column: string) {
+ return !!this.viewConfig?.columns?.find(col => col.value === column)?.keepCollapsed;
+ }
+
+ /**
+ * Sets whether a column collapses again once it has been opened.
+ *
+ * Turning it on collapses the column as well, so that the entry does something the reader can
+ * see rather than only deciding what happens the next time the column is opened.
+ *
+ * @param isOpen whether the column is drawn open. Turning the flag off then clears `collapsed`
+ * as well, so the column the reader is looking at stays open.
+ */
+ async setColumnKeepCollapsed(column: string, keepCollapsed: boolean, isOpen = false) {
+ if (keepCollapsed) {
+ this.updateColumn(column, { keepCollapsed: true, collapsed: true });
+ return;
+ }
+
+ this.updateColumn(column,
+ isOpen ? { keepCollapsed: false, collapsed: false } : { keepCollapsed: false });
+ }
+
/**
* Writes properties onto a column, dropping each one given as nothing so that it goes back to
* its default rather than being stored empty.
@@ -552,6 +576,7 @@ export default class BoardApi {
if (!updated.color) delete updated.color;
if (!updated.archived) delete updated.archived;
if (!updated.collapsed) delete updated.collapsed;
+ if (!updated.keepCollapsed) delete updated.keepCollapsed;
if (!updated.displayName) delete updated.displayName;
if (!updated.limit) delete updated.limit;
return updated;
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 9514e7320a..14881fff02 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -52,6 +52,7 @@ export default function Column({
color,
archived,
collapsed,
+ keepCollapsed,
isActive,
nested,
limit,
@@ -68,8 +69,10 @@ export default function Column({
color?: string,
/** Whether the column is archived. Only ever rendered while archived notes are shown. */
archived?: boolean,
- /** Whether the column is stored as collapsed. Selecting it opens it without clearing this. */
+ /** Whether the column is stored as collapsed. A drag opening it does not clear this. */
collapsed?: boolean,
+ /** Whether the column collapses again once opened, which keeps `collapsed` through an open. */
+ keepCollapsed?: boolean,
/** Whether this is the column the reader is working in, which opens it while it is collapsed. */
isActive?: boolean,
/** Whether the inbox also collects notes deeper than the board's direct children. */
@@ -117,6 +120,7 @@ export default function Column({
const { branchIdToEdit, columnNameToEdit, dropTarget, draggedCard, dropPosition } = useContext(BoardDragStateContext);
const isEditing = (columnNameToEdit === column);
const editorRef = useRef<HTMLInputElement>(null);
+ const headerRef = useRef<HTMLHeadingElement>(null);
const contentRef = useRef<HTMLDivElement>(null);
const scrollFade = useScrollFade(contentRef);
// Cards slide to follow the drop gap opening and closing. Only the card named by `created`
@@ -143,10 +147,47 @@ export default function Column({
const isOverLimit = limit !== undefined && (columnItems?.length ?? 0) > limit;
const isCollapsed = !!collapsed && !isActive;
+ // Only while the column is open: the strip's own press opens it, which is what it says
+ // instead. Memoised because `useStaticTooltip` rebuilds the tooltip on a new config.
+ const headerTooltip = useMemo(
+ () => ({ title: isCollapsed ? "" : t("board_view.collapse-hint") }), [ isCollapsed ]);
+ useStaticTooltip(headerRef, headerTooltip);
+
// Reported on the way in only. A column opened by being selected closes when another one is
// selected, so nothing here watches for focus leaving: the menu, the icon picker and the limit
// dialog all render outside the column, and each would otherwise close it as it opened.
- const select = useCallback(() => setActiveColumn(column), [ column, setActiveColumn ]);
+ const select = useCallback(() => {
+ setActiveColumn(column);
+
+ // Opening the strip by hand opens the column for good, unless `keepCollapsed` says it
+ // closes again. A column opened by a card dragged over it goes through `setActiveColumn`
+ // instead, so it keeps the flag.
+ if (isCollapsed && !keepCollapsed) {
+ api.setColumnCollapsed(column, false);
+ }
+ }, [ api, column, isCollapsed, keepCollapsed, setActiveColumn ]);
+
+ /**
+ * Whether the collapse now being drawn is one the reader asked for, which runs faster than a
+ * peek closing: only the peek closes behind the pointer, with the board shifting under it.
+ */
+ const [ isCollapsingByHand, setIsCollapsingByHand ] = useState(false);
+
+ /** Collapses the column, closing the open one so that the change is drawn straight away. */
+ const collapse = useCallback(() => {
+ setIsCollapsingByHand(true);
+ api.setColumnCollapsed(column, true);
+ setActiveColumn(undefined);
+ }, [ api, column, setActiveColumn ]);
+
+ /**
+ * Whether the header was a strip when the press began.
+ *
+ * The first click of a double click on a strip already opens the column, so by the time
+ * `dblclick` arrives the header is a heading and collapsing it again would undo the open. Only
+ * the press that starts a sequence is recorded, which `detail` counts.
+ */
+ const wasCollapsedOnPress = useRef(false);
// 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.
@@ -165,6 +206,8 @@ export default function Column({
archived,
collapsed,
canRename: !isCollapsed,
+ isCollapsed,
+ keepCollapsed,
nested,
onEditTitle: () => setColumnNameToEdit(column),
onNewItem: () => setIsCreatingNewItem(true),
@@ -172,11 +215,13 @@ export default function Column({
setColumnNameToEdit(await api.insertColumn(column, direction));
},
onSetLimit: () => setColumnLimitToEdit(column),
- onCollapse: (collapse) => {
- api.setColumnCollapsed(column, collapse);
- // The menu is opened from the column, which is therefore the open one. Closing it
- // here is what shows the reader that anything happened.
- if (collapse) {
+ onCollapse: collapse,
+ onKeepCollapsed: (keep) => {
+ setIsCollapsingByHand(keep);
+ api.setColumnKeepCollapsed(column, keep, !isCollapsed);
+ // Turning it on collapses the column as well, so the open one is closed here for
+ // the same reason `collapse` closes it.
+ if (keep) {
setActiveColumn(undefined);
}
},
@@ -188,8 +233,9 @@ export default function Column({
}
});
}, [
- api, column, color, archived, collapsed, isCollapsed, nested, columns, columnIndex,
- setColumnNameToEdit, setColumnLimitToEdit, setActiveColumn, onMoveColumn, onFocusColumn
+ api, column, color, archived, collapsed, keepCollapsed, collapse, isCollapsed, nested,
+ columns, columnIndex, setColumnNameToEdit, setColumnLimitToEdit, setActiveColumn,
+ onMoveColumn, onFocusColumn
]);
// A fully desaturated colour has no hue to tint with, and leaves the column plain.
@@ -215,6 +261,12 @@ export default function Column({
}
}, []);
+ useEffect(() => {
+ if (!isCollapsed) {
+ setIsCollapsingByHand(false);
+ }
+ }, [ isCollapsed ]);
+
useEffect(() => {
editorRef.current?.focus();
}, [ isEditing ]);
@@ -229,6 +281,7 @@ export default function Column({
"board-column-archived": archived,
"over-limit": isOverLimit,
collapsed: isCollapsed,
+ "quick-collapse": isCollapsingByHand,
appearing: isNew && !isRevealed
})}
onAnimationEnd={(e) => {
@@ -246,6 +299,7 @@ export default function Column({
style={{ "--board-column-custom-hue": hue }}
>
<h3
+ 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
@@ -253,6 +307,16 @@ export default function Column({
role={isCollapsed ? "button" : undefined}
aria-expanded={isCollapsed ? false : undefined}
onContextMenu={openMenu}
+ onMouseDown={(e) => {
+ if (e.detail <= 1) {
+ wasCollapsedOnPress.current = isCollapsed;
+ }
+ }}
+ onDblClick={() => {
+ if (!wasCollapsedOnPress.current) {
+ collapse();
+ }
+ }}
onKeyDown={handleTitleKeyDown}
tabIndex={300}
>
@@ -293,14 +357,7 @@ export default function Column({
{!isEditing ? (
<>
- <span
- className="title"
- // In relation mode the title is a link to the note the column stands
- // for, and the first of the two clicks has already followed it.
- onDblClick={isInRelationMode
- ? undefined
- : () => setColumnNameToEdit(column)}
- >
+ <span className="title">
{isInRelationMode
? <NoteLink notePath={column} showNoteIcon />
: api.getColumnTitle(column)}
diff --git a/apps/client/src/widgets/collections/board/context_menu.spec.ts b/apps/client/src/widgets/collections/board/context_menu.spec.ts
index 5ab8aff0d6..4c8f82f54e 100644
--- a/apps/client/src/widgets/collections/board/context_menu.spec.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.spec.ts
@@ -32,7 +32,8 @@ describe("Board column context menu", () => {
api: BoardApi,
column: {
value?: string, color?: string, archived?: boolean, collapsed?: boolean,
- canRename?: boolean, columns?: string[], index?: number, nested?: boolean
+ keepCollapsed?: boolean, isCollapsed?: boolean, canRename?: boolean,
+ columns?: string[], index?: number, nested?: boolean
} = {},
callbacks: {
onEditTitle?: () => void,
@@ -40,7 +41,8 @@ describe("Board column context menu", () => {
onAddColumn?: (direction: "before" | "after") => void,
onMoveColumn?: (toIndex: number) => void,
onSetLimit?: () => void,
- onCollapse?: (collapsed: boolean) => void
+ onCollapse?: (collapsed: boolean) => void,
+ onKeepCollapsed?: (keepCollapsed: boolean) => void
} = {}
) {
const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
@@ -64,7 +66,8 @@ describe("Board column context menu", () => {
onAddColumn: callbacks.onAddColumn ?? (() => {}),
onMoveColumn: callbacks.onMoveColumn ?? (() => {}),
onSetLimit: callbacks.onSetLimit ?? (() => {}),
- onCollapse: callbacks.onCollapse ?? (() => {})
+ onCollapse: callbacks.onCollapse ?? (() => {}),
+ onKeepCollapsed: callbacks.onKeepCollapsed ?? (() => {})
});
// The spy outlives one call, so it is the menu just opened that is read back.
@@ -119,13 +122,26 @@ describe("Board column context menu", () => {
expect(api.setColumnArchived).toHaveBeenLastCalledWith("To Do", false);
});
- /** One entry that carries the state, rather than two that swap places under the pointer. */
- it("offers one collapse entry, checked while the column is collapsed", () => {
+ /** Collapsing is what the entry does; whether the column stays collapsed is the other one. */
+ it("collapses the column, and offers nothing to collapse while it is a strip", () => {
const onCollapse = vi.fn();
- const entryOf = (collapsed: boolean) => {
- const found = openMenu({} as BoardApi, { collapsed }, { onCollapse }).find(item =>
- item && "uiIcon" in item && item.uiIcon === "bx bx-collapse-horizontal");
- if (!found || !("handler" in found)) throw new Error("expected a collapse entry");
+ const entry = openMenu({} as BoardApi, {}, { onCollapse }).find(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-collapse-horizontal");
+ if (!entry || !("handler" in entry)) throw new Error("expected a collapse entry");
+
+ entry.handler?.(entry, {} as never);
+ expect(onCollapse).toHaveBeenLastCalledWith(true);
+
+ expect(openMenu({} as BoardApi, { isCollapsed: true }).some(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-collapse-horizontal")).toBe(false);
+ });
+
+ it("carries the keep-collapsed state, and reports the entry as checked", () => {
+ const onKeepCollapsed = vi.fn();
+ const entryOf = (keepCollapsed: boolean) => {
+ const found = openMenu({} as BoardApi, { keepCollapsed }, { onKeepCollapsed })
+ .find(item => item && "uiIcon" in item && item.uiIcon === "bx bx-lock-alt");
+ if (!found || !("handler" in found)) throw new Error("expected a keep entry");
return found;
};
@@ -133,12 +149,12 @@ describe("Board column context menu", () => {
const unchecked = entryOf(false);
expect("trailingIcon" in unchecked && unchecked.trailingIcon).toBeUndefined();
unchecked.handler?.(unchecked, {} as never);
- expect(onCollapse).toHaveBeenLastCalledWith(true);
+ expect(onKeepCollapsed).toHaveBeenLastCalledWith(true);
const checked = entryOf(true);
expect("trailingIcon" in checked && checked.trailingIcon).toBe("bx bx-check");
checked.handler?.(checked, {} as never);
- expect(onCollapse).toHaveBeenLastCalledWith(false);
+ expect(onKeepCollapsed).toHaveBeenLastCalledWith(false);
});
/** The strip has no title to edit, so the menu does not offer to edit one either. */
@@ -152,7 +168,7 @@ describe("Board column context menu", () => {
expect(icons(true)).toContain("bx bx-edit-alt");
expect(icons(false)).not.toContain("bx bx-edit-alt");
// Everything else the menu offers is still there.
- expect(icons(false)).toContain("bx bx-collapse-horizontal");
+ expect(icons(false)).toContain("bx bx-lock-alt");
expect(icons(false)).toContain("bx bx-trash");
});
@@ -205,7 +221,7 @@ describe("Board column context menu", () => {
const titled = openMenu({} as BoardApi).filter(item => item && "uiIcon" in item);
expect(titled.map(item => "uiIcon" in item ? item.uiIcon : undefined))
.toEqual([
- "bx bx-edit-alt", "bx bx-collapse-horizontal", "bx bx-tachometer",
+ "bx bx-edit-alt", "bx bx-collapse-horizontal", "bx bx-lock-alt", "bx bx-tachometer",
"bx bx-plus", "bx bx-link",
"bx bx-columns", "bx bx-horizontal-left", "bx bx-archive", "bx bx-trash"
]);
diff --git a/apps/client/src/widgets/collections/board/context_menu.ts b/apps/client/src/widgets/collections/board/context_menu.ts
index 6098072588..b76bb47e72 100644
--- a/apps/client/src/widgets/collections/board/context_menu.ts
+++ b/apps/client/src/widgets/collections/board/context_menu.ts
@@ -23,8 +23,12 @@ interface ColumnMenuTarget {
index: number;
color?: string;
archived?: boolean;
- /** Whether the column is stored as collapsed, which the menu offers to undo. */
+ /** Whether the column is stored as collapsed. */
collapsed?: boolean;
+ /** Whether the column collapses again once it has been opened. */
+ keepCollapsed?: boolean;
+ /** Whether the column is drawn as a strip right now, which is what the menu offers to do. */
+ isCollapsed?: boolean;
/** Whether the title can be edited, which the strip a collapsed column is drawn as cannot. */
canRename: boolean;
/** Whether the inbox also collects notes deeper than the board's direct children. */
@@ -39,8 +43,10 @@ interface ColumnMenuTarget {
onMoveColumn: (toIndex: number) => void;
/** Opens the dialog that sets the column's note limit. */
onSetLimit: () => void;
- /** Collapses the column or opens it for good, the board drawing the change straight away. */
+ /** Collapses the column, the board drawing the change straight away. */
onCollapse: (collapsed: boolean) => void;
+ /** Sets whether the column collapses again once it has been opened. */
+ onKeepCollapsed: (keepCollapsed: boolean) => void;
}
export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column: ColumnMenuTarget) {
@@ -59,11 +65,18 @@ export function openColumnContextMenu(api: Api, event: ContextMenuEvent, column:
shortcut: "F2",
handler: column.onEditTitle
} ] : []),
- {
+ // Nothing to collapse while the column is already drawn as a strip.
+ ...(column.isCollapsed ? [] : [ {
title: t("board_view.collapse-column"),
uiIcon: "bx bx-collapse-horizontal",
- trailingIcon: column.collapsed ? "bx bx-check" : undefined,
- handler: () => column.onCollapse(!column.collapsed)
+ handler: () => column.onCollapse(true)
+ } ]),
+ {
+ title: t("board_view.keep-column-collapsed"),
+ uiIcon: "bx bx-lock-alt",
+ // At the trailing edge, the entry keeping its own icon ahead of it.
+ trailingIcon: column.keepCollapsed ? "bx bx-check" : undefined,
+ handler: () => column.onKeepCollapsed(!column.keepCollapsed)
},
{
title: t("board_view.set-limit"),
diff --git a/apps/client/src/widgets/collections/board/drag.spec.tsx b/apps/client/src/widgets/collections/board/drag.spec.tsx
index 62568d5482..c9659d59a9 100644
--- a/apps/client/src/widgets/collections/board/drag.spec.tsx
+++ b/apps/client/src/widgets/collections/board/drag.spec.tsx
@@ -165,6 +165,20 @@ describe("Board drag and drop", () => {
expect(columns[0].classList.contains("collapsed")).toBe(false);
});
+ /**
+ * The drag opens the column, the reader does not, so the stored flag stays as it is: the
+ * column is a strip again once the card has been dropped and another column is selected.
+ */
+ it("writes nothing when a dragged card opens a collapsed column", async () => {
+ const saveConfig = vi.fn();
+ const { columns } = await renderBoard({ collapsed: true, saveConfig });
+
+ await drag(columns[0], "dragover", { types: [ TREE_CLIPBOARD_TYPE ] }, 50);
+
+ expect(columns[0].classList.contains("collapsed")).toBe(false);
+ expect(saveConfig).not.toHaveBeenCalled();
+ });
+
/**
* What the gesture is for: the same move the old clipboard drop made, made by pointer. The
* board's own wiring is what this covers, the gesture itself being tested on its own.
@@ -309,7 +323,9 @@ describe("Board drag and drop", () => {
}
/** A board of one column of two cards, each given a height the pointer can be placed in. */
- async function renderBoard({ collapsed }: { collapsed?: boolean } = {}) {
+ async function renderBoard(
+ { collapsed, saveConfig }: { collapsed?: boolean, saveConfig?: () => void } = {}
+ ) {
const note = buildNote({
title: "Board",
"#collection": "",
@@ -333,7 +349,7 @@ describe("Board drag and drop", () => {
noteIds={[ ...note.getChildNoteIds() ]}
highlightedTokens={null}
viewConfig={{ columns: [ { value: "To Do", collapsed } ] }}
- saveConfig={() => {}}
+ saveConfig={saveConfig ?? (() => {})}
media="screen"
onReady={() => {}}
/>
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index e244328361..ae65ccb098 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -17,6 +17,7 @@
its side. */
--board-collapsed-column-width: 2.25em;
--board-collapse-duration: 1s;
+ --board-collapse-duration-quick: 0.3s;
--board-focus-outline-saturation: 55%;
--board-focus-outline-lightness: 45%;
@@ -722,6 +723,12 @@ body.mobile .column-drop-placeholder {
width var(--board-collapse-duration) ease;
}
+/* A collapse the reader asked for surprises nobody, so it runs faster than a peek closing behind
+ the pointer. */
+.board-view-container .board-column.collapsed.quick-collapse {
+ --board-collapse-duration: var(--board-collapse-duration-quick);
+}
+
@media (prefers-reduced-motion: reduce) {
.board-view-container .board-column.collapsed {
transition: border-color 0.2s ease;
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 5bb8641105..83b432dfca 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -143,7 +143,7 @@ describe("Collapsed board columns", () => {
});
/** A board whose first column is stored collapsed and holds two cards. */
- async function setup() {
+ async function setup({ keepCollapsed = false } = {}) {
const note = buildNote({
title: "Board",
"#collection": "",
@@ -166,7 +166,10 @@ describe("Collapsed board columns", () => {
note={note}
noteIds={[ ...note.getChildNoteIds() ]}
initialConfig={{ columns: [
- { value: "To Do", collapsed: true }, { value: "Done" }
+ { value: "To Do", collapsed: true, ...(keepCollapsed
+ ? { keepCollapsed: true }
+ : {}) },
+ { value: "Done" }
] }}
/>
</ParentComponent.Provider>,
@@ -221,7 +224,7 @@ describe("Collapsed board columns", () => {
});
it("opens the column when it is selected and closes it when another one is", async () => {
- const { mountPoint } = await setup();
+ const { mountPoint } = await setup({ keepCollapsed: true });
await select(mountPoint, 0);
expect(isCollapsed(mountPoint, 0)).toBe(false);
@@ -285,7 +288,7 @@ describe("Collapsed board columns", () => {
});
it("closes an open column when focus reaches another one", async () => {
- const { mountPoint } = await setup();
+ const { mountPoint } = await setup({ keepCollapsed: true });
await select(mountPoint, 0);
expect(isCollapsed(mountPoint, 0)).toBe(false);
@@ -303,7 +306,7 @@ describe("Collapsed board columns", () => {
* focus leaving it is not a reason to close it. Only another column being selected is.
*/
it("stays open while a control rendered outside it is used", async () => {
- const { mountPoint } = await setup();
+ const { mountPoint } = await setup({ keepCollapsed: true });
await select(mountPoint, 0);
expect(isCollapsed(mountPoint, 0)).toBe(false);
@@ -321,10 +324,97 @@ describe("Collapsed board columns", () => {
expect(isCollapsed(mountPoint, 0)).toBe(false);
});
- it("opens a collapsed column without writing anything", async () => {
+ /**
+ * A column collapsed by hand is opened by hand, the way it is in most boards: the stored flag
+ * goes with the open, so the column does not shut again the moment another one is selected.
+ */
+ it("opens a collapsed column for good, clearing the stored flag", async () => {
const { mountPoint } = await setup();
- // Opening it by selection is not a change to the config, so nothing is written at all.
+ await select(mountPoint, 0);
+ expect(isCollapsed(mountPoint, 0)).toBe(false);
+ expect(saved.at(-1)?.columns?.[0]).toEqual({ value: "To Do" });
+
+ // Selecting another one no longer takes it back.
+ await select(mountPoint, 1);
+ expect(isCollapsed(mountPoint, 0)).toBe(false);
+ });
+
+ /**
+ * A peek closes behind the pointer, with the columns beside it shifting under it, so it eases
+ * shut; a collapse the reader asked for surprises nobody and runs faster.
+ */
+ it("marks a collapse the reader asked for, and leaves a peek closing unmarked", async () => {
+ const { mountPoint } = await setup({ keepCollapsed: true });
+
+ await select(mountPoint, 0);
+ await act(async () => {
+ columnAt(mountPoint, 0).querySelector("h3")
+ ?.dispatchEvent(new MouseEvent("dblclick", { bubbles: true, detail: 2 }));
+ await flush();
+ });
+ expect(isCollapsed(mountPoint, 0)).toBe(true);
+ expect(columnAt(mountPoint, 0).classList.contains("quick-collapse")).toBe(true);
+
+ // Opened again, what closes it is the peek, which is not the reader asking for it.
+ await select(mountPoint, 0);
+ expect(columnAt(mountPoint, 0).classList.contains("quick-collapse")).toBe(false);
+
+ await select(mountPoint, 1);
+ expect(isCollapsed(mountPoint, 0)).toBe(true);
+ expect(columnAt(mountPoint, 0).classList.contains("quick-collapse")).toBe(false);
+ });
+
+ /**
+ * The reader is looking at the open column when the entry is unchecked, so the column stays
+ * open: shutting it the moment another one is selected would read as the entry doing nothing.
+ */
+ it("keeps a peeked column open once it is no longer kept collapsed", async () => {
+ const { mountPoint } = await setup({ keepCollapsed: true });
+
+ await select(mountPoint, 0);
+ expect(isCollapsed(mountPoint, 0)).toBe(false);
+
+ const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
+ columnAt(mountPoint, 0).querySelector("h3")
+ ?.dispatchEvent(new MouseEvent("contextmenu", { bubbles: true }));
+ const entry = (show.mock.calls.at(-1)?.[0].items ?? []).find(item =>
+ item && "uiIcon" in item && item.uiIcon === "bx bx-lock-alt");
+ if (!entry || !("handler" in entry)) throw new Error("expected a keep-collapsed entry");
+
+ await act(async () => {
+ entry.handler?.(entry, {} as never);
+ await flush();
+ });
+ show.mockRestore();
+
+ expect(saved.at(-1)?.columns?.[0]).toEqual({ value: "To Do" });
+ await select(mountPoint, 1);
+ expect(isCollapsed(mountPoint, 0)).toBe(false);
+ });
+
+ /** The first of the two clicks opens the strip; collapsing it again would undo that. */
+ it("leaves a strip open when it is double clicked open", async () => {
+ const { mountPoint } = await setup();
+ const header = columnAt(mountPoint, 0).querySelector("h3");
+
+ await act(async () => {
+ header?.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, detail: 1 }));
+ header?.dispatchEvent(new MouseEvent("click", { bubbles: true, detail: 1 }));
+ await flush();
+ });
+ await act(async () => {
+ header?.dispatchEvent(new MouseEvent("mousedown", { bubbles: true, detail: 2 }));
+ header?.dispatchEvent(new MouseEvent("dblclick", { bubbles: true, detail: 2 }));
+ await flush();
+ });
+
+ expect(isCollapsed(mountPoint, 0)).toBe(false);
+ });
+
+ it("keeps the flag through an open where the column is kept collapsed", async () => {
+ const { mountPoint } = await setup({ keepCollapsed: true });
+
await select(mountPoint, 0);
expect(isCollapsed(mountPoint, 0)).toBe(false);
expect(saved).toEqual([]);
@@ -853,17 +943,20 @@ describe("Board column rename", () => {
expect(columnTitles(mountPoint)).toEqual([ "To Do", "Doing" ]);
});
- it("opens the title editor when the title is double clicked", async () => {
+ it("collapses the column when its header is double clicked", async () => {
const { container } = await setup();
const [ first ] = [ ...container.querySelectorAll<HTMLElement>(".board-column") ];
await act(async () => {
- first.querySelector(".title")
+ first.querySelector("h3")
?.dispatchEvent(new MouseEvent("dblclick", { bubbles: true }));
+ await flush();
});
- expect(first.querySelector("h3")?.classList.contains("editing")).toBe(true);
- expect(first.querySelector("h3 input")).not.toBeNull();
+ expect(first.classList.contains("collapsed")).toBe(true);
+ expect(saved.at(-1)?.columns?.[0]).toEqual({ value: "To Do", collapsed: true });
+ // The title editor is left to F2 and to the menu.
+ expect(first.querySelector("h3 input")).toBeNull();
});
/** The tooltip is set on the element, which is where `useStaticTooltip` reads it back from. */
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 0dbd6b95ae..a4232094fb 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -59,6 +59,12 @@ export interface BoardColumnData {
* it again until another one is selected, which does not change this.
*/
collapsed?: boolean;
+ /**
+ * Whether the column collapses again after being opened. Without it, opening a collapsed
+ * column by hand clears `collapsed`; a column opened to take a dragged card is unaffected
+ * either way.
+ */
+ keepCollapsed?: boolean;
/**
* Whether the inbox column also collects notes below the board's direct children. Has no
* meaning on any other column, which is defined by a grouping value instead.
@@ -639,6 +645,7 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
color={storedColumns.get(column)?.color}
archived={storedColumns.get(column)?.archived}
collapsed={storedColumns.get(column)?.collapsed}
+ keepCollapsed={storedColumns.get(column)?.keepCollapsed}
isActive={activeColumn === column}
nested={storedColumns.get(column)?.nested}
limit={storedColumns.get(column)?.limit}
diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
index d9e1441292..d41467425f 100644
--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx
+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
@@ -380,6 +380,9 @@ describe("Board keyboard", () => {
expect(columnAt(board, 1).classList.contains("collapsed")).toBe(false);
expect(focusedName(board)).toBe("Third");
+ // Opened by hand, so the column stays open rather than shutting behind the reader.
+ expect(saved.at(-1)?.columns?.find(col => col.value === "Doing")?.collapsed)
+ .toBeUndefined();
});
/** Nothing to step onto, so the column opens and focus stays where it was. */
diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.ts
index b5536e0b13..641b2c3b70 100644
--- a/apps/client/src/widgets/collections/board/keyboard.ts
+++ b/apps/client/src/widgets/collections/board/keyboard.ts
@@ -224,6 +224,11 @@ export function useBoardKeyboard({
take(e);
setActiveColumn(column);
+ // Opening the strip by hand opens the column for good, as a click on it does.
+ if (!api.isColumnKeptCollapsed(column)) {
+ api.setColumnCollapsed(column, false);
+ }
+
// The cards are drawn only once the column opens, so the first of them is asked for
// rather than focused here; the effect above puts focus on it as it appears. The
// header gives focus up for that, the effect leaving alone anything the reader is