Skip to content

Build your personal knowledge base with Trilium Notes

client/collections/board: don't expand a card when tapped on mobile

Adorian Dorane23dcc9065c0
diff --git a/apps/client/src/widgets/collections/board/column.tsx b/apps/client/src/widgets/collections/board/column.tsx
index da7550ef13..0a2669be64 100644
--- a/apps/client/src/widgets/collections/board/column.tsx
+++ b/apps/client/src/widgets/collections/board/column.tsx
@@ -403,7 +403,7 @@ export default function Column({
// 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(() => {
+ const expand = useCallback(() => {
setActiveColumn(column);
// Opening the strip by hand opens the column for good, unless `keepCollapsed` says it
@@ -414,6 +414,20 @@ export default function Column({
}
}, [ api, column, isCollapsed, keepCollapsed, setActiveColumn ]);
+ /**
+ * What a press on the column does. On a touch screen a collapsed strip only takes the focus,
+ * which brings its rail up: the rail carries the button that opens it, so a tap aimed at the
+ * rail cannot open the column on the way.
+ */
+ const select = useCallback(() => {
+ if (isMobile() && isCollapsed) {
+ headerRef.current?.focus();
+ return;
+ }
+
+ expand();
+ }, [ expand, isCollapsed ]);
+
/**
* 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.
@@ -858,7 +872,7 @@ export default function Column({
isLeaving={!isRailShown}
isCollapsed={isCollapsed}
onRename={() => setColumnNameToEdit(column)}
- onToggleCollapse={isCollapsed ? select : collapse}
+ onToggleCollapse={isCollapsed ? expand : collapse}
onSort={(e) => openColumnSortMenu(api, e.pageX, e.pageY, column)}
onFocusOut={handleHeaderFocusOut}
/>
diff --git a/apps/client/src/widgets/collections/board/index.spec.tsx b/apps/client/src/widgets/collections/board/index.spec.tsx
index a69390c79c..0a5cbcb6a1 100644
--- a/apps/client/src/widgets/collections/board/index.spec.tsx
+++ b/apps/client/src/widgets/collections/board/index.spec.tsx
@@ -5501,6 +5501,24 @@ describe("Column toolbar on mobile", () => {
expect(buttons()).toEqual([ "bx-edit-alt", "bx-collapse-horizontal", "bx-sort-alt-2" ]);
});
+ /**
+ * A tap lands on a strip on the way to the rail standing over it, so it brings the rail up and
+ * leaves the column as it is. Only the rail's own button opens it.
+ */
+ it("leaves a strip collapsed when it is tapped, and opens it from the rail", async () => {
+ await setup();
+ await act(async () => { heading(0).focus(); });
+ await act(async () => { button("bx-collapse-horizontal").click(); });
+ expect(column(0).classList.contains("collapsed")).toBe(true);
+
+ await act(async () => { column(0).dispatchEvent(new Event("click", { bubbles: true })); });
+ expect(column(0).classList.contains("collapsed")).toBe(true);
+ expect(buttons()).toEqual([ "bx-expand-horizontal" ]);
+
+ await act(async () => { button("bx-expand-horizontal").click(); });
+ expect(column(0).classList.contains("collapsed")).toBe(false);
+ });
+
it("opens the sort menu and the title editor", async () => {
await setup();
const show = vi.spyOn(contextMenu, "show").mockImplementation(async () => {});