Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: fix some issues

Adorian Doran8edac03ea208
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index 373995b72d..7e53644f40 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -100,24 +100,6 @@ export default function Column({
// dialog all render outside the column, and each would otherwise close it as it opened.
const select = useCallback(() => setActiveColumn(column), [ column, setActiveColumn ]);
- // A press on the header may be the start of a drag, which must leave the column as it is: the
- // strip is what the reader takes hold of to move it. A click settles which one it was, a drag
- // producing none. Focus arriving while the pointer is down is that same press, so only focus
- // reached by keyboard opens the column.
- const isPointerDown = useRef(false);
- const handlePointerDown = useCallback(() => {
- isPointerDown.current = true;
-
- const release = () => {
- isPointerDown.current = false;
- controller.abort();
- };
- // A drag ends with `dragend` and no `pointerup` at all, so both have to release it.
- const controller = new AbortController();
- document.addEventListener("pointerup", release, { signal: controller.signal });
- document.addEventListener("dragend", release, { signal: controller.signal });
- }, []);
-
// 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(() => {
@@ -212,7 +194,8 @@ export default function Column({
collapsed: isCollapsed
})}
onFocusIn={handleFocusIn}
- onPointerDown={handlePointerDown}
+ // A click and not a press: a press may be the start of a drag, which must leave the
+ // column as it is, and a drag produces no click.
onClick={select}
onDragOver={isAnyColumnDragging ? handleColumnDragOver : handleDragOver}
onDragLeave={handleDragLeave}
@@ -224,6 +207,11 @@ export default function Column({
>
<h3
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.
+ role={isCollapsed ? "button" : undefined}
+ aria-expanded={isCollapsed ? false : undefined}
draggable
onDragStart={handleColumnDragStart}
onDragEnd={handleColumnDragEnd}
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index a995e50870..e6883d3333 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -59,8 +59,8 @@ body.mobile .board-view-container {
/* A column with no colour of its own is painted rather than composed: the tinted shades come
from one lightness, which does not answer for a plain one as well. */
background-color: var(--board-column-background);
- /* Opening is instant, so a click or a drag reaches the cards at once. Closing is eased below:
- the transition that runs is the one the element carries once the class has changed. */
+ /* Must stay 0s: the transition that runs is the one carried after the class changes, so this is
+ what makes opening instant while `.collapsed` below eases the close. */
transition: border-color 0.2s ease, width 0s;
overflow-y: auto;
max-height: 100%;
@@ -537,8 +537,7 @@ body.mobile .board-view-container .board-add-column {
.board-view-container .board-column.collapsed {
width: var(--board-collapsed-column-width);
overflow: hidden;
- /* Width is what the columns beside it are placed against, so easing it is what makes them slide
- rather than jump. Nothing composited can do this: the shift is the point. */
+ /* Width and not a transform: the columns beside it have to move with it. */
transition: border-color 0.2s ease, width var(--board-collapse-duration) ease;
}
@@ -548,8 +547,7 @@ body.mobile .board-view-container .board-add-column {
}
}
-/* The strip is the whole column, so what is focused is ringed round the column. Round the header
- inside it the ring would be clipped, an element's own overflow cutting off its descendants. */
+/* On the column, not the header: `overflow: hidden` above would clip a descendant's outline. */
.board-view-container .board-column.collapsed:focus-within {
outline: 3px solid var(--board-focus-outline-color, var(--board-focus-outline-plain-color));
outline-offset: 0;
@@ -559,8 +557,7 @@ body.mobile .board-view-container .board-add-column {
outline: none;
}
-/* The strip's own width, taken at once, so the header stands where it will end up and only the
- space beside it shrinks. */
+/* Matches the strip, so the header does not drift sideways while the column narrows. */
.board-view-container .board-column.collapsed h3 {
width: var(--board-collapsed-column-width);
flex-direction: column;
@@ -569,23 +566,22 @@ body.mobile .board-view-container .board-add-column {
border-bottom: none;
}
-/* The header stacks, so the margins that spaced these out in a row would throw them off centre. */
+/* The header stacks, so margins meant for a row would throw these off centre. */
.board-view-container .board-column.collapsed h3 > .column-icon,
.board-view-container .board-column.collapsed h3 > .column-menu,
.board-view-container .board-column.collapsed h3 > .counter-badge {
margin: 0;
}
-/* The title and the count are turned on their side and read from the bottom up. `sideways-lr`
- says this in one word, but is too new to rely on, so the box is turned the rest of the way
- instead. The menu button keeps its own orientation. */
+/* Read from the bottom up. `sideways-lr` says this in one word but is too new to rely on, so the
+ box is turned the rest of the way. */
.board-view-container .board-column.collapsed h3 > .title,
.board-view-container .board-column.collapsed h3 > .counter-badge {
writing-mode: vertical-rl;
transform: rotate(180deg);
}
-/* The pill turns with the count, so its padding is swapped to keep it as narrow as the strip. */
+/* Swapped: `padding` is physical, so it does not turn with the count. */
.board-view-container .board-column.collapsed h3 > .counter-badge {
padding: 0.6em 0.1em;
}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 3d136dab37..d881906b97 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -241,6 +241,27 @@ describe("Collapsed board columns", () => {
expect(isCollapsed(mountPoint, 0)).toBe(false);
});
+ /**
+ * A collapsed column draws none of its cards, so nothing but the header is left to announce.
+ * It says it opens something and what state that is in, rather than reading as a heading with
+ * no way past it.
+ */
+ it("announces the strip as a control that opens the column", async () => {
+ const { mountPoint } = await setup();
+ const header = () => columnAt(mountPoint, 0).querySelector("h3");
+
+ expect(header()?.getAttribute("role")).toBe("button");
+ expect(header()?.getAttribute("aria-expanded")).toBe("false");
+
+ // Open, it is a heading again: Space does nothing there, so no button is promised.
+ await select(mountPoint, 0);
+ expect(header()?.getAttribute("role")).toBeNull();
+ expect(header()?.getAttribute("aria-expanded")).toBeNull();
+
+ // A column that was never collapsed says nothing either way.
+ expect(columnAt(mountPoint, 1).querySelector("h3")?.getAttribute("role")).toBeNull();
+ });
+
/** The header is walked onto without opening the column, which Space is for. */
it("leaves the column closed when focus reaches its header", async () => {
const { mountPoint } = await setup();
@@ -330,6 +351,42 @@ describe("Collapsed board columns", () => {
expect(saved.at(-1)?.columns?.[1]).toEqual({ value: "Done", collapsed: true });
});
+ /**
+ * The board is not drawn afresh for another note, so the column opened on one is still named
+ * in its state when the next arrives. A board of its own storing a column under that name
+ * would be drawn open, against what it stores.
+ */
+ it("does not carry an open column over to another board", async () => {
+ const { mountPoint } = await setup();
+
+ await select(mountPoint, 0);
+ expect(isCollapsed(mountPoint, 0)).toBe(false);
+
+ const other = buildNote({
+ title: "Other board",
+ "#collection": "",
+ "#viewType": "board",
+ children: [ { title: "Fourth", "#status": "To Do" } ]
+ });
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={new Component()}>
+ <Harness
+ note={other}
+ noteIds={[ ...other.getChildNoteIds() ]}
+ initialConfig={{ columns: [ { value: "To Do", collapsed: true } ] }}
+ />
+ </ParentComponent.Provider>,
+ mountPoint
+ );
+ await flush();
+ });
+ await act(async () => { await flush(); });
+
+ expect(isCollapsed(mountPoint, 0)).toBe(true);
+ expect(cardCount(mountPoint, 0)).toBe(0);
+ });
+
it("offers no icon picker or title editor while collapsed", async () => {
const { mountPoint } = await setup();
const collapsed = columnAt(mountPoint, 0);
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 0c558d55ad..810c442427 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -330,6 +330,10 @@ export default function BoardView({ note: parentNote, noteIds, viewConfig, saveC
});
}
+ // The board is not drawn afresh for another note, so the column opened on one would otherwise
+ // still be open on the next, over whatever that board stores for a column of the same name.
+ useEffect(() => setActiveColumn(undefined), [ parentNote ]);
+
useEffect(refresh, [
parentNote, noteIds, viewConfig, statusAttributeWithPrefix, statusDefinition, inboxEnabled
]);
diff --git a/apps/client/src/widgets/collections/board/keyboard.spec.tsx b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
index 8cd5669c6c..896f57ddae 100644
--- a/apps/client/src/widgets/collections/board/keyboard.spec.tsx
+++ b/apps/client/src/widgets/collections/board/keyboard.spec.tsx
@@ -337,13 +337,26 @@ describe("Board keyboard", () => {
expect(document.activeElement).toBe(columnAt(board, 2).querySelector("h3"));
});
- it("leaves Space alone on a column that is not collapsed", async () => {
+ it("opens it with Enter too, the header being announced as a button", async () => {
+ const board = await renderBoard("Doing");
+ focusHeader(board, 1);
+
+ press(board, "Enter");
+ await act(async () => { await flush(); });
+
+ expect(columnAt(board, 1).classList.contains("collapsed")).toBe(false);
+ expect(focusedName(board)).toBe("Third");
+ });
+
+ it("leaves Space and Enter alone on a column that is not collapsed", async () => {
const board = await renderBoard();
focusHeader(board, 1);
press(board, " ");
+ press(board, "Enter");
expect(document.activeElement).toBe(columnAt(board, 1).querySelector("h3"));
+ expect(columnAt(board, 1).querySelectorAll(".board-note")).toHaveLength(1);
});
});
diff --git a/apps/client/src/widgets/collections/board/keyboard.ts b/apps/client/src/widgets/collections/board/keyboard.ts
index c7b92e0628..872c2b9ac2 100644
--- a/apps/client/src/widgets/collections/board/keyboard.ts
+++ b/apps/client/src/widgets/collections/board/keyboard.ts
@@ -213,10 +213,10 @@ export function useBoardKeyboard({
return;
}
- if (e.key === " " && spot.kind === "header") {
+ // Both keys, the collapsed header answering for a button and being announced as one.
+ if ((e.key === " " || e.key === "Enter") && spot.kind === "header") {
const column = columns[spot.column];
- const element = container.querySelector(`.board-column[data-column="${CSS.escape(column)}"]`);
- if (!element?.classList.contains("collapsed")) return;
+ if (!columnsOf(container)[spot.column]?.classList.contains("collapsed")) return;
take(e);
setActiveColumn(column);