Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: add a backdrop for the cards being edited

Adorian Doran7b4f2fa5d5e3
diff --git a/apps/client/src/widgets/collections/board/card.spec.tsx b/apps/client/src/widgets/collections/board/card.spec.tsx
index f9ea137aeb..2db6343182 100644
--- a/apps/client/src/widgets/collections/board/card.spec.tsx
+++ b/apps/client/src/widgets/collections/board/card.spec.tsx
@@ -387,6 +387,33 @@ describe("Board card", () => {
expect(element.querySelector(".user-attributes")).toBeTruthy();
});
+ /**
+ * The wash over the board is raised by the stylesheet from the classes checked here, since each
+ * field keeps its own state and there is nothing above them all to read. These are the names it
+ * goes by; the wash itself is a rule that `happy-dom` lays nothing out for.
+ */
+ it("marks what a backdrop is raised for while a title is being typed", async () => {
+ const { first } = await renderBoard();
+ expect(container?.querySelector(".board-edit-backdrop")).toBeTruthy();
+ // Held on to: the editor takes the place of the title the lookup goes by.
+ const element = card(first);
+
+ await act(async () => { press(element, "F2"); });
+ expect(element.classList.contains("editing")).toBe(true);
+
+ const editor = element.querySelector<HTMLTextAreaElement>("textarea");
+ if (!editor) throw new Error("expected the title editor");
+ await act(async () => { press(editor, "Escape"); });
+ expect(element.classList.contains("editing")).toBe(false);
+
+ // The field that opens between two cards is marked; the one at the foot of the column is
+ // left as it is, and raises nothing.
+ await act(async () => { press(element, "Enter"); });
+ expect(container?.querySelectorAll(".board-new-item.inserting")).toHaveLength(1);
+ expect(container?.querySelector(".board-new-item:not(.inserting)")?.classList
+ .contains("inserting")).toBe(false);
+ });
+
it("offers the card menu on a right click", async () => {
const { first } = await renderBoard();
const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});
diff --git a/apps/client/src/widgets/collections/board/index.css b/apps/client/src/widgets/collections/board/index.css
index 8f02ea1a3e..3010778630 100644
--- a/apps/client/src/widgets/collections/board/index.css
+++ b/apps/client/src/widgets/collections/board/index.css
@@ -33,6 +33,9 @@
--board-drag-ring-width: 3px;
/* The ring a picked-out card carries. */
--board-selected-ring-color: var(--link-color);
+ /* The wash the board goes behind while a card is being named. Light: it is there to draw the
+ eye to the field, not to shut the board off. */
+ --board-edit-backdrop: rgba(0, 0, 0, 0.15);
--board-focus-outline-saturation: 55%;
--board-focus-outline-lightness: 45%;
@@ -653,6 +656,60 @@ body.mobile .board-view-container .board-add-column {
padding: 0;
}
+/* The board behind the card being named.
+ *
+ * A sibling of the scrolling container rather than a child, so it covers the board as it stands
+ * rather than as far as it scrolls. Nothing between a card and here opens a stacking context, so
+ * the card lifts through it on a `z-index` of its own. */
+.board-view .board-edit-backdrop {
+ position: absolute;
+ inset: 0;
+ z-index: 50;
+ background-color: var(--board-edit-backdrop);
+ opacity: 0;
+ pointer-events: none;
+ transition: opacity 0.3s ease;
+}
+
+/* Read off the field itself rather than from the board's state: a new item's field is the column's
+ own business, and the one that opens between two cards is a third piece of state again.
+ `inserting` is that one alone, so the field at the foot of a column raises nothing. */
+.board-view:has(.board-note.editing, .board-new-item.inserting) .board-edit-backdrop {
+ opacity: 1;
+}
+
+.board-view-container .board-note.editing,
+.board-view-container .board-new-item.inserting {
+ z-index: 51;
+}
+
+/* While a title is being typed the board stops answering the pointer: a card neither lights up
+ under it nor takes a press, so leaving the field cannot also open a note or pick a card out.
+ `:hover` follows hit testing rather than any event, so this is the only thing that takes it away.
+ The columns themselves are left alone, which is what keeps the board scrolling, and the field is
+ excluded rather than re-enabled below: this rule outweighs a plainer one, and the field would go
+ inert with everything else.
+
+ It restyles every card on the board, which is a few hundred milliseconds on a board of thousands,
+ and is why it waits for `frozen` rather than following the wash: done in the same frame the wash
+ begins in, that recalculation eats the fade whole. */
+.board-view.frozen :is(
+ .board-column > h3,
+ .board-column > .board-new-item,
+ .board-column-content > *:not(.editing)
+) {
+ pointer-events: none;
+}
+
+/* The fade a column draws over its edges is a mask, and a mask holds everything under it in a
+ layer of its own, which the field being typed into could not rise out of. Taken off the one
+ column that holds it, for as long as it stands. `!important` because `useScrollFade` writes the
+ mask on the element itself. */
+.board-view-container .board-column:has(.board-note.editing, .board-new-item.inserting)
+ .board-column-content {
+ mask: none !important;
+}
+
/* A card being edited stacks the field over what it shows, rather than standing them side by side:
the badges are drawn either way, so the card keeps its own height as the editor opens. */
.board-view-container .board-note.editing {
diff --git a/apps/client/src/widgets/collections/board/index.tsx b/apps/client/src/widgets/collections/board/index.tsx
index 48e18c9969..dff41f4e17 100644
--- a/apps/client/src/widgets/collections/board/index.tsx
+++ b/apps/client/src/widgets/collections/board/index.tsx
@@ -386,6 +386,8 @@ export default function BoardView({
/** Everything a card could be made from: the note types and every template. */
const availableTemplates = useNoteTypeOptions();
const [ isEditingProperties, setIsEditingProperties ] = useState(false);
+ /** Whether the board has stopped answering the pointer, which the wash arriving is what sets. */
+ const [ isFrozen, setIsFrozen ] = useState(false);
const selectColumn = useCallback<Dispatch<StateUpdater<string | undefined>>>((column) => {
setIsPeekingAll(false);
setActiveColumn(column);
@@ -1137,7 +1139,18 @@ export default function BoardView({
: undefined;
return (
- <div className="board-view">
+ <div className={clsx("board-view", { frozen: isFrozen })}>
+ {/* Stands over the board while a title is being typed, with the field lifted through
+ it. Always drawn, so it fades in rather than appearing. Which fields raise it is
+ the stylesheet's to say, since each keeps its own state.
+
+ The board is frozen once the wash has arrived rather than as it starts: freezing
+ restyles every card, which in the same frame would eat the fade whole. */}
+ <div
+ className="board-edit-backdrop"
+ onTransitionEnd={(e) => setIsFrozen(
+ getComputedStyle(e.currentTarget as HTMLElement).opacity === "1")}
+ />
<CollectionProperties
note={parentNote}
rightChildren={<>