Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: implement a side toolbar for the selected item on the mobile layout

Adorian Doranfcaec2fb0fd5
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index df5fc91ecf..758a24d7fa 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3569,7 +3569,8 @@
"sort-board-default": "Board's default",
"reset-column-sorting": "Reset sorting options to default for all columns",
"reset-column-sorting-confirm": "Do you want to reset the sorting options for all columns from the current view to default?",
- "sorted-no-reorder": "Cards cannot be reordered, since this is a sorted column."
+ "sorted-no-reorder": "Cards cannot be reordered, since this is a sorted column.",
+ "more-actions": "More actions"
},
"dashboard_view": {
"refresh-widget": "Refresh",
diff --git a/apps/client/src/widgets/collections/board/board_drag.spec.tsx b/apps/client/src/widgets/collections/board/board_drag.spec.tsx
index bebf248764..7f4a316c60 100644
--- a/apps/client/src/widgets/collections/board/board_drag.spec.tsx
+++ b/apps/client/src/widgets/collections/board/board_drag.spec.tsx
@@ -388,17 +388,31 @@ describe("useBoardDrag, carrying a card", () => {
expect(captured).toEqual([ 1 ]);
});
- /** A tap asks for the menu, the long press being how a finger picks a card up instead. */
- it("asks a card for its menu when it is tapped", () => {
+ /**
+ * A tap on a card is a click on it, which opens the card. The long press is how a finger
+ * picks a card up, so no menu is asked for on the way.
+ */
+ it("leaves a tap on a card to the click it lands", () => {
setup();
const element = card("n1");
const menus: string[] = [];
+ const clicks: boolean[] = [];
element.addEventListener("contextmenu", () => menus.push("card"));
+ board.addEventListener("click", (event) => clicks.push(event.defaultPrevented));
press(element, 50, 60, "touch");
release(50, 62, "touch");
+ act(() => {
+ element.dispatchEvent(new Event("click", { bubbles: true, cancelable: true }));
+ });
- expect(menus).toEqual([ "card" ]);
+ expect(menus).toEqual([]);
+ expect(clicks).toEqual([ false ]);
+
+ // Nor is the `touchend` the browser makes the click from refused.
+ const followed = new Event("touchend", { bubbles: true, cancelable: true });
+ act(() => { document.dispatchEvent(followed); });
+ expect(followed.defaultPrevented).toBe(false);
});
/** The heading answers for a column's menu, the column itself holding no handler. */
@@ -440,16 +454,17 @@ describe("useBoardDrag, carrying a card", () => {
expect(clicks).toEqual([ "click" ]);
});
- it("leaves the click a tap also lands unanswered", () => {
+ it("leaves the click a tap on a heading also lands unanswered", () => {
setup();
- const element = card("n1");
+ const heading = board.querySelector<HTMLElement>(".board-column h3");
+ if (!heading) throw new Error("expected a heading");
const clicks: boolean[] = [];
board.addEventListener("click", (event) => clicks.push(event.defaultPrevented));
- press(element, 50, 60, "touch");
- release(50, 62, "touch");
+ press(heading, 10, 10, "touch");
+ release(11, 11, "touch");
act(() => {
- element.dispatchEvent(new Event("click", { bubbles: true, cancelable: true }));
+ heading.dispatchEvent(new Event("click", { bubbles: true, cancelable: true }));
});
expect(clicks).toEqual([]);
@@ -462,9 +477,11 @@ describe("useBoardDrag, carrying a card", () => {
*/
it("refuses the mouse events a browser would make from a tap", () => {
setup();
+ const heading = board.querySelector<HTMLElement>(".board-column h3");
+ if (!heading) throw new Error("expected a heading");
- press(card("n1"), 50, 60, "touch");
- release(50, 62, "touch");
+ press(heading, 10, 10, "touch");
+ release(11, 11, "touch");
const followed = new Event("touchend", { bubbles: true, cancelable: true });
act(() => { document.dispatchEvent(followed); });
diff --git a/apps/client/src/widgets/collections/board/board_drag.ts b/apps/client/src/widgets/collections/board/board_drag.ts
index a4060c9609..8e4e02e71b 100644
--- a/apps/client/src/widgets/collections/board/board_drag.ts
+++ b/apps/client/src/widgets/collections/board/board_drag.ts
@@ -491,14 +491,16 @@ export function useBoardDrag(
<= TOUCH_TOLERANCE;
const dragged = held.active && event.type === "pointerup";
const target = held.menuTarget;
- // A tap on a collapsed column opens it: that is what the strip is for, and its menu is
- // on the button it carries. Everything else answers a tap with its menu, the long
- // press that would otherwise open one being how a finger picks something up.
- const opens = target.closest(".board-column")?.classList.contains("collapsed");
+ // A tap on a card is left to the click it lands, which opens the card, and a tap on a
+ // collapsed column opens it: that is what the strip is for, and its menu is on the
+ // button it carries. A column's heading answers a tap with its menu, the long press
+ // that would otherwise open one being how a finger picks something up.
+ const isLeftToClick = held.kind === "card"
+ || target.closest(".board-column")?.classList.contains("collapsed");
close(event.type === "pointercancel");
- if (tapped && !opens) {
+ if (tapped && !isLeftToClick) {
// The browser follows a tap with mouse events for pages that know nothing of touch,
// and they land on the menu this is about to open, right under the finger: the
// first of them takes the menu straight back off again. Refused at `touchend`,
diff --git a/apps/client/src/widgets/collections/board/card.tsx b/apps/client/src/widgets/collections/board/card.tsx
index f3c952098c..1c72247f03 100644
--- a/apps/client/src/widgets/collections/board/card.tsx
+++ b/apps/client/src/widgets/collections/board/card.tsx
@@ -9,12 +9,14 @@ import FNote from "../../../entities/fnote";
import BoardApi, { CARD_REDIRECT_RELATION } from "./api";
import {
BoardActionsContext, BoardHighlightTokensContext, BoardKeptCardsContext,
- BoardPromotedAttributesContext, TitleEditor
+ BoardOverlayHostContext, BoardPromotedAttributesContext, TitleEditor
} from ".";
import { ContextMenuEvent } from "../../../menus/context_menu";
import { cardFollows } from "./columns";
import { openNoteContextMenu } from "./context_menu";
+import branches from "../../../services/branches";
import { t } from "../../../services/i18n";
+import { isMobile } from "../../../services/utils";
import UserAttributesDisplay from "../../attribute_widgets/UserAttributesList";
import { parseNavigationStateFromUrl } from "../../../services/link";
import { FLIP_SETTLE_MS } from "../../react/flip";
@@ -26,6 +28,7 @@ import { TooltipIcon } from "../../react/Icon";
import { HighlightedText } from "../../react/RawHtml";
import { useIsSelected, useSelection } from "../../react/selection";
import { type DragData, TREE_CLIPBOARD_TYPE } from "../../note_tree";
+import CardToolbar from "./card_toolbar";
function Card({
api,
@@ -95,6 +98,18 @@ function Card({
// card and no other. The store keeps one identity for the life of the board, so holding it
// here leaves the memo below intact.
const selection = useSelection();
+ const overlayHost = useContext(BoardOverlayHostContext);
+ /** Whether the card holds the focus, which on mobile floats its toolbar over the board. */
+ const [ isFocused, setIsFocused ] = useState(false);
+ // Focus moving within the card or onto the toolbar keeps the toolbar; anywhere else takes it.
+ const handleFocusOut = useCallback((e: FocusEvent) => {
+ const next = e.relatedTarget instanceof Element ? e.relatedTarget : null;
+ if (next && (cardRef.current?.contains(next) || next.closest(".board-card-toolbar"))) {
+ return;
+ }
+
+ setIsFocused(false);
+ }, []);
const isSelected = useIsSelected(note.noteId);
// A card owns its own title: the board does not redraw for a note-row change. Setting the value
@@ -253,7 +268,7 @@ function Card({
return () => window.clearTimeout(settled);
}, [ isNew ]);
- return (
+ return (<>
<div
ref={cardRef}
className={clsx("board-note", colorClass, {
@@ -275,6 +290,8 @@ function Card({
onDragStart={handleDragStart}
onClick={!isEditing ? handleClick : undefined}
onKeyDown={handleKeyDown}
+ onFocusIn={() => setIsFocused(true)}
+ onFocusOut={handleFocusOut}
tabIndex={300}
>
{!isEditing ? (
@@ -316,7 +333,25 @@ function Card({
badges={isOutsideFilter && <OutsideFilterBadge />}
/>
</div>
- )
+ {/* Off the card while its title is edited, since the rename it offers is under way, and
+ while it is carried, since the board is being rearranged under the finger. */}
+ {isMobile() && isFocused && !isEditing && !isDragging && overlayHost.current && (
+ <CardToolbar
+ host={overlayHost.current}
+ isSorted={api.isColumnSorted(column)}
+ removal={api.isInboxEnabled ? "note" : "board"}
+ onRename={() => setBranchIdToEdit(branch.branchId)}
+ onInsertAbove={() => onInsert(index)}
+ onInsertBelow={() => onInsert(index + 1)}
+ onInsertNew={onNewItem}
+ onRemove={() => (api.isInboxEnabled
+ ? branches.deleteNotes([ branch.branchId ], false, false)
+ : api.removeFromBoard([ note.noteId ]))}
+ onMore={handleContextMenu}
+ onFocusOut={handleFocusOut}
+ />
+ )}
+ </>);
}
/**
diff --git a/apps/client/src/widgets/collections/board/card_toolbar.css b/apps/client/src/widgets/collections/board/card_toolbar.css
new file mode 100644
index 0000000000..a084bf7a6d
--- /dev/null
+++ b/apps/client/src/widgets/collections/board/card_toolbar.css
@@ -0,0 +1,45 @@
+/* Laid out by the group, which pins itself over the board: the wrapper is there for its events. */
+.board-view-container .board-card-toolbar {
+ display: contents;
+}
+
+/* Nothing is offered while a card is carried; the rail comes back with the focus afterwards. */
+.board-view-container.dragging .board-card-toolbar {
+ display: none;
+}
+
+.board-view-container .board-card-toolbar .tn-overlay-control-group {
+ /* A finger's target: 48px square meets Material, Apple's 44pt and WCAG 2.5.5 alike. */
+ --overlay-button-height: 48px;
+ --overlay-button-icon-size: 24px;
+ /* Flush with the screen edge, so a touch reaching for the rail cannot land on a card past it. */
+ --overlay-group-inset-end: 0;
+ z-index: 2;
+ border-inline-end: none;
+ border-start-end-radius: 0;
+ border-end-end-radius: 0;
+
+ .tn-overlay-icon-button {
+ width: 48px;
+ }
+
+ /* Takes the card away, and is marked the way destructive menu entries are. */
+ .board-remove-button {
+ color: var(--dropdown-item-icon-destructive-color);
+ }
+
+ /* The side that meets the screen edge keeps no rounding. */
+ button:first-child {
+ border-start-end-radius: 0;
+ }
+
+ button:last-child {
+ border-end-end-radius: 0;
+ }
+}
+
+/* The icon above it turned over: an addition at the foot of the list rather than at its head. */
+.board-view-container .board-card-toolbar .board-insert-below-button::before {
+ display: inline-block;
+ transform: scaleY(-1);
+}
diff --git a/apps/client/src/widgets/collections/board/card_toolbar.tsx b/apps/client/src/widgets/collections/board/card_toolbar.tsx
new file mode 100644
index 0000000000..0eb78d3809
--- /dev/null
+++ b/apps/client/src/widgets/collections/board/card_toolbar.tsx
@@ -0,0 +1,100 @@
+import "./card_toolbar.css";
+
+import { createPortal } from "preact/compat";
+
+import { t } from "../../../services/i18n";
+import OverlayControlGroup, { OverlayControlButton } from "../../react/OverlayControlGroup";
+
+interface CardToolbarProps {
+ /** The board's element, which the toolbar floats over rather than the card it belongs to. */
+ host: HTMLElement;
+ /** Whether the column places its cards itself, which leaves one place to insert at. */
+ isSorted: boolean;
+ /**
+ * What taking the card away means: off the board, or the note deleted. A board with an inbox
+ * keeps a card whose grouping value is cleared, so deleting the note is what takes it off.
+ */
+ removal: "board" | "note";
+ onRename: () => void;
+ onInsertAbove: () => void;
+ onInsertBelow: () => void;
+ /** Inserts at the foot of a sorted column, which places the card itself. */
+ onInsertNew: () => void;
+ onRemove: () => void;
+ /** Opens the card's context menu, at the button. */
+ onMore: (event: MouseEvent) => void;
+ /** Reports focus leaving the toolbar, for the card to decide whether the toolbar stays. */
+ onFocusOut: (event: FocusEvent) => void;
+}
+
+/**
+ * What can be done with the focused card, on a rail flush with the board's trailing edge.
+ *
+ * Mobile only: a finger has no right button for the card's menu, and a tap opens the card. The rail
+ * follows the focus, and is hidden while a card is carried (see card_toolbar.css).
+ */
+export default function CardToolbar({
+ host, isSorted, removal, onRename, onInsertAbove, onInsertBelow, onInsertNew, onRemove,
+ onMore, onFocusOut
+}: CardToolbarProps) {
+ return createPortal(
+ <div
+ className="board-card-toolbar"
+ // A press must not move the focus off the card, which would close the toolbar under
+ // the finger, nor reach the board, which would take it for the start of a pan.
+ onPointerDown={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ }}
+ onFocusOut={onFocusOut}
+ >
+ <OverlayControlGroup placement="middle-end" vertical overCanvas>
+ <OverlayControlButton
+ title={t("board_view.edit-title")}
+ icon="bx-rename"
+ onClick={onRename}
+ />
+ {isSorted ? (
+ <OverlayControlButton
+ title={t("board_view.insert-new")}
+ icon="bx-plus"
+ onClick={onInsertNew}
+ />
+ ) : (<>
+ <OverlayControlButton
+ title={t("board_view.insert-above")}
+ icon="bx-list-plus"
+ onClick={onInsertAbove}
+ />
+ <OverlayControlButton
+ title={t("board_view.insert-below")}
+ icon="bx-list-plus"
+ className="board-insert-below-button"
+ onClick={onInsertBelow}
+ />
+ </>)}
+ {removal === "board" ? (
+ <OverlayControlButton
+ title={t("board_view.remove-from-board")}
+ icon="bx-task-x"
+ className="board-remove-button"
+ onClick={onRemove}
+ />
+ ) : (
+ <OverlayControlButton
+ title={t("board_view.delete-note")}
+ icon="bx-trash"
+ className="board-remove-button"
+ onClick={onRemove}
+ />
+ )}
+ <OverlayControlButton
+ title={t("board_view.more-actions")}
+ icon="bx-dots-vertical-rounded"
+ onClick={onMore}
+ />
+ </OverlayControlGroup>
+ </div>,
+ host
+ );
+}
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index 2e69cf555f..cfbeb35efa 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -19,6 +19,7 @@ import toast from "../../../services/toast";
import FBranch from "../../../entities/fbranch";
import froca from "../../../services/froca";
import attributes from "../../../services/attributes";
+import branches from "../../../services/branches";
import { executeBulkActions } from "../../../services/bulk_action";
import LoadResults from "../../../services/load_results";
import noteAttributeCache from "../../../services/note_attribute_cache";
@@ -47,6 +48,15 @@ vi.mock("../../../services/i18n", () => ({
// the picker and hands one over when it is pressed.
// What a card can be made from. The listing itself is the app's and is tested there; the board is
// handed a short list of it, the four it offers by default and one it does not.
+// Hoisted with the mock, which is lifted above everything a test file declares.
+const layout = vi.hoisted(() => ({ onMobile: false }));
+
+// Spread rather than replaced: the board reads far more of this than the one export a test steers.
+vi.mock("../../../services/utils", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("../../../services/utils")>()),
+ isMobile: () => layout.onMobile
+}));
+
vi.mock("../../../services/note_types", () => ({
getNoteTypeOptions: vi.fn(async () => {
templateReads++;
@@ -4384,9 +4394,9 @@ describe("Board properties from the note menu", () => {
}
// A modal Bootstrap still believes is shown traps the focus of every later test, and its
- // teardown waits on a transition happy-dom never runs.
- const modal = document.querySelector<HTMLElement>(".board-properties-dialog");
- if (modal) {
+ // teardown waits on a transition happy-dom never runs. Every one of them: earlier tests
+ // leave dialogs of their own behind, and the shown one is the last.
+ for (const modal of document.querySelectorAll<HTMLElement>(".board-properties-dialog")) {
BootstrapModal.getInstance(modal)?.dispose();
modal.remove();
}
@@ -4742,3 +4752,221 @@ describe("what the board hands the right pane", () => {
expect(cleared).toContain("boardColumns");
});
});
+
+describe("Card toolbar on mobile", () => {
+ let container: HTMLElement;
+ let host: Component;
+
+ beforeEach(() => {
+ layout.onMobile = true;
+ });
+
+ afterEach(() => {
+ layout.onMobile = false;
+ vi.useRealTimers();
+ saved.length = 0;
+ render(null, container);
+ container.remove();
+ });
+
+ /** A board of two columns, three cards, nothing sorted, and an inbox only when asked for. */
+ async function setup({ withInbox = false } = {}) {
+ // A dialog an earlier test opened can be mounted only after that test's teardown, and a
+ // modal Bootstrap believes shown pulls the focus back into itself from anything focused
+ // later. The toolbar follows the focus, so the page is cleared of them first.
+ for (const modal of document.querySelectorAll<HTMLElement>(".modal.show")) {
+ BootstrapModal.getInstance(modal)?.dispose();
+ modal.remove();
+ }
+ document.querySelector(".modal-backdrop")?.remove();
+ document.body.classList.remove("modal-open");
+
+ const note = buildNote({
+ title: "Board",
+ "#collection": "",
+ "#viewType": "board",
+ ...(withInbox ? { "#enableInboxColumn": "true" } : {}),
+ children: [
+ { id: "tool1", title: "First", "#status": "To Do" },
+ { id: "tool2", title: "Second", "#status": "To Do" },
+ { id: "tool3", title: "Third", "#status": "Done" }
+ ]
+ });
+
+ host = new Component();
+ container = document.body.appendChild(document.createElement("div"));
+ await act(async () => {
+ render(
+ <ParentComponent.Provider value={host}>
+ <Harness
+ note={note}
+ noteIds={[ ...note.getChildNoteIds() ]}
+ initialConfig={{ columns: [ { value: "To Do" }, { value: "Done" } ] }}
+ />
+ </ParentComponent.Provider>,
+ container
+ );
+ });
+ await act(async () => { await flush(); });
+
+ return note;
+ }
+
+ function card(noteId: string) {
+ const element = container.querySelector<HTMLElement>(
+ `.board-note[data-note-id="${noteId}"]`);
+ if (!element) throw new Error(`expected the card ${noteId}`);
+ return element;
+ }
+
+ const toolbar = () => container.querySelector<HTMLElement>(".board-card-toolbar");
+
+ /** The buttons on the rail, each by the icon it wears. */
+ const buttons = () => [ ...toolbar()?.querySelectorAll("button") ?? [] ]
+ .map(button => [ ...button.classList ].find(name => name.startsWith("bx-")));
+
+ function button(icon: string) {
+ const element = toolbar()?.querySelector<HTMLElement>(`button.${icon}`);
+ if (!element) throw new Error(`expected a ${icon} button`);
+ return element;
+ }
+
+ async function focus(noteId: string) {
+ await act(async () => { card(noteId).focus(); });
+ }
+
+ /**
+ * Runs a step with a tab manager standing in for the app's, which the card's menu and the
+ * reveal after a drop ask for the active pane. Only for that step: the board's own hooks read
+ * the manager while it renders, and answer differently to a stand-in than to none.
+ */
+ async function withTabManager(step: () => Promise<void>) {
+ const previous = appContext.tabManager;
+ appContext.tabManager = {
+ getActiveContext: () => undefined,
+ // The menu on mobile asks whether the pane is split, which one with no splits is not.
+ getNoteContextById: () => ({ getMainContext: () => ({ getSubContexts: () => [] }) })
+ } as never;
+ try {
+ await step();
+ } finally {
+ appContext.tabManager = previous;
+ }
+ }
+
+ it("follows the focus onto a card and leaves with it, over the board", async () => {
+ await setup();
+ expect(toolbar()).toBeNull();
+ await focus("tool1");
+ expect(buttons()).toEqual([
+ "bx-rename", "bx-list-plus", "bx-list-plus", "bx-task-x", "bx-dots-vertical-rounded"
+ ]);
+ // The second insert is the one below, told apart by the class its icon is turned over by.
+ expect(toolbar()?.querySelectorAll("button")[2].classList
+ .contains("board-insert-below-button")).toBe(true);
+ // Portaled onto the board, whose edge the rail is pinned to, rather than into the card.
+ expect(toolbar()?.parentElement).toBe(container.querySelector(".board-view-container"));
+
+ // A press on the rail keeps the focus where it is, or the rail would close under it.
+ const press = new PointerEvent("pointerdown", { bubbles: true, cancelable: true });
+ button("bx-rename").dispatchEvent(press);
+ expect(press.defaultPrevented).toBe(true);
+
+ await act(async () => { card("tool1").blur(); });
+ expect(toolbar()).toBeNull();
+ });
+
+ it("is left out off mobile, where the card has its menu", async () => {
+ layout.onMobile = false;
+ await setup();
+
+ await focus("tool1");
+ expect(toolbar()).toBeNull();
+ });
+
+ it("inserts, renames, removes and opens the menu for the focused card", async () => {
+ await setup();
+ const removeFromBoard = vi.spyOn(BoardApi.prototype, "removeFromBoard")
+ .mockResolvedValue(undefined);
+ const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
+
+ // Insert below opens the field under the card, which takes the focus and the rail with it.
+ await focus("tool1");
+ await act(async () => {
+ button("board-insert-below-button").click();
+ await flush();
+ });
+ const column = container.querySelectorAll(".board-column")[0];
+ const order = [ ...column.querySelectorAll(".board-note, .board-new-item.inserting") ]
+ .map(element => element.getAttribute("data-note-id") ?? "field");
+ expect(order).toEqual([ "tool1", "field", "tool2" ]);
+ expect(toolbar()).toBeNull();
+
+ // Rename opens the title editor in the card, and the rail stands aside while it is open.
+ await focus("tool2");
+ await act(async () => { button("bx-rename").click(); });
+ expect(card("tool2").classList.contains("editing")).toBe(true);
+ expect(toolbar()).toBeNull();
+
+ await focus("tool3");
+ await withTabManager(async () => {
+ await act(async () => { button("bx-dots-vertical-rounded").click(); });
+ });
+ expect(show).toHaveBeenCalledTimes(1);
+
+ await act(async () => { button("bx-task-x").click(); });
+ expect(removeFromBoard).toHaveBeenCalledWith([ "tool3" ]);
+
+ removeFromBoard.mockRestore();
+ show.mockRestore();
+ });
+
+ /**
+ * A board with an inbox keeps a card whose grouping value is cleared, in the inbox, so what
+ * takes a card off such a board is deleting the note, as on the card's menu.
+ */
+ it("offers to delete the note instead where the board has an inbox", async () => {
+ await setup({ withInbox: true });
+ const deleteNotes = vi.spyOn(branches, "deleteNotes").mockResolvedValue(false);
+
+ await focus("tool1");
+ expect(buttons()).toEqual([
+ "bx-rename", "bx-list-plus", "bx-list-plus", "bx-trash", "bx-dots-vertical-rounded"
+ ]);
+
+ // The card's own branch, and neither the tree's confirmation shortcut nor its erase.
+ await act(async () => { button("bx-trash").click(); });
+ expect(deleteNotes.mock.calls).toEqual([ [ [ expect.any(String) ], false, false ] ]);
+
+ deleteNotes.mockRestore();
+ });
+
+ /**
+ * A long press picks the card up, and nothing is offered while it is carried. Let go where it
+ * was picked up, the card takes the focus back, and the rail with it.
+ */
+ it("is hidden while the card is carried, and back once the press lets go", async () => {
+ await setup();
+ await focus("tool1");
+ vi.useFakeTimers();
+
+ const element = card("tool1");
+ const press = (type: string) => element.dispatchEvent(new PointerEvent(type, {
+ bubbles: true, pointerType: "touch", clientX: 10, clientY: 10
+ }));
+ const board = () => container.querySelector(".board-view-container");
+
+ await act(async () => {
+ press("pointerdown");
+ vi.advanceTimersByTime(1000);
+ });
+ expect(board()?.classList.contains("dragging")).toBe(true);
+
+ await withTabManager(async () => {
+ await act(async () => { press("pointerup"); });
+ });
+ expect(board()?.classList.contains("dragging")).toBe(false);
+ expect(document.activeElement).toBe(card("tool1"));
+ expect(toolbar()).not.toBeNull();
+ });
+});
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 0f301ea94d..b2a26eb82c 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -266,6 +266,9 @@ export const BoardHighlightTokensContext = createContext<HighlightedTokenInfo[]
/** The cards drawn although the filter does not match them, which say as much on their face. */
export const BoardKeptCardsContext = createContext<Set<string>>(new Set());
+/** The board's own element, which what a card floats over the board is portaled into. */
+export const BoardOverlayHostContext = createContext<RefObject<HTMLElement>>({ current: null });
+
/**
* What the board answers with when asked for contextual keyboard help. Every entry is a key the
* board handles itself (see `keyboard.ts` and the card and column handlers), none of them
@@ -1360,11 +1363,13 @@ export default function BoardView({
<BoardDropStateContext.Provider value={dropState}>
<BoardDragStateContext.Provider value={boardDragState}>
<SelectionContext.Provider value={selection}>
+ <BoardOverlayHostContext.Provider value={containerRef}>
{byColumn && columns && <div
ref={containerRef}
className={clsx("board-view-container", {
pannable: isPannable,
- panning: isPanning
+ panning: isPanning,
+ dragging: isDraggingItem
})}
onKeyDown={handleKeyDown}
onClick={clearSelectionOutsideCards}
@@ -1486,6 +1491,7 @@ export default function BoardView({
</OverlayControlGroup>
)}
</div>}
+ </BoardOverlayHostContext.Provider>
</SelectionContext.Provider>
</BoardDragStateContext.Provider>
</BoardDropStateContext.Provider>