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 a column sometimes scrolling the past the last item
Adorian Dorana5df878db14a
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsxindex 57f692880a..f5ea28ef0f 100644--- a/apps/client/src/widgets/collections/board/column.tsx+++ b/apps/client/src/widgets/collections/board/column.tsx@@ -285,6 +285,8 @@ export default function Column({: (last ? last.offsetTop + last.offsetHeight + cardSpacing() : 0));gap.style.transform = `translateY(${top}px)`;gap.style.height = `${height}px`;+ } else {+ clearGap(gap);}gap.classList.toggle("show", dropIndex !== null);roomRef.current?.style.setProperty("height", `${room}px`);@@ -843,6 +845,19 @@ export function placeCard(card: HTMLElement, transform: string | null, atOnce: b});}+/**+ * Takes back the room a closed gap holds in its column.+ *+ * `.board-drop-placeholder` is positioned in the column's scrolling box, so its height and+ * transform count towards `scrollHeight` whether it is showing or not. Left where the last drag+ * put it, it holds a card's worth of scroll past the last card.+ */+export function clearGap(gap: HTMLElement) {+ gap.style.removeProperty("transform");+ // Set rather than removed: the stylesheet gives the gap a height of its own to fall back on.+ gap.style.height = "0px";+}+/*** Puts back at once the suppressed transitions of the cards one board holds, for a board leaving* the page.diff --git a/apps/client/src/widgets/collections/board/drag.spec.tsx b/apps/client/src/widgets/collections/board/drag.spec.tsxindex 4c5984f80c..4589b5c2d9 100644--- a/apps/client/src/widgets/collections/board/drag.spec.tsx+++ b/apps/client/src/widgets/collections/board/drag.spec.tsx@@ -88,7 +88,10 @@ describe("Board drag and drop", () => {// unmade, which is what keeps a drag off the board's own contents.await drag(columns[0], "dragleave", { types: [] });expect(columns[0].querySelector(".board-drop-placeholder.show")).toBeNull();- expect(columns[0].querySelector(".board-drop-placeholder")).toBeTruthy();+ const gap = columns[0].querySelector<HTMLElement>(".board-drop-placeholder");+ expect(gap).toBeTruthy();+ // Standing at no height, so the column scrolls no further than its last card.+ expect(gap?.style.height).toBe("0px");});/**@@ -395,6 +398,30 @@ describe("Board drag and drop", () => {expect(gap?.style.height).toBe("100px");});+ /**+ * The gap is positioned in the column's scrolling box, so its height and transform count+ * towards `scrollHeight` whether it is showing or not. Left where the drag put it, the column+ * scrolls a card's worth past its last card.+ */+ it("takes back the room the gap held once the card is let go", async () => {+ const { columns } = await renderBoard();+ const card = columns[0].querySelector<HTMLElement>(".board-note");+ if (!card) throw new Error("expected a card");+ await act(async () => { await settle(); });++ await pointer(card, "pointerdown", 50, 50);+ await pointer(columns[0], "pointermove", 50, 120);++ const gap = columns[0].querySelector<HTMLElement>(".board-drop-placeholder");+ if (!gap) throw new Error("expected a gap");+ expect(gap.style.height).toBe("100px");++ await pointer(columns[0], "pointerup", 50, 120);++ expect(gap.style.height).toBe("0px");+ expect(gap.style.transform).toBe("");+ });+/*** The card leaves the flow as it is lifted, and the gap opens in its place by pushing the cards* below it down again. Under their transition that reads as the column closing up and thendiff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsxindex 2d7827170d..18c8929c72 100644--- a/apps/client/src/widgets/collections/board/index.tsx+++ b/apps/client/src/widgets/collections/board/index.tsx@@ -59,7 +59,7 @@ import {COLUMN_WIDTH_LABEL, columnWidthClass, DEFAULT_COLUMN_ICON, DEFAULT_GROUP_BY,getStatusDefinition, INBOX_COLUMN} from "./columns";-import Column, { EXPAND_MS, placeCard, settleCards } from "./column";+import Column, { clearGap, EXPAND_MS, placeCard, settleCards } from "./column";import { currentCardTemplate, DEFAULT_CARD_TEMPLATES } from "./card_templates";import ColumnLimitDialog from "./column_limit";import BoardGroupBy, { groupingOptions } from "./group_by";@@ -1465,8 +1465,9 @@ function closeGaps(container: HTMLElement | null) {}}- for (const gap of container.querySelectorAll(".board-drop-placeholder")) {+ for (const gap of container.querySelectorAll<HTMLElement>(".board-drop-placeholder")) {gap.classList.remove("show");+ clearGap(gap);}for (const room of container.querySelectorAll<HTMLElement>(".board-drop-room")) {