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
fix(attributes): pick rows on a phone with the desktop's checkbox
Elian Doran6fb9d92e9bcc
diff --git a/apps/client/src/widgets/dialogs/note_attributes.css b/apps/client/src/widgets/dialogs/note_attributes.cssindex f219ea084b..82a81ce803 100644--- a/apps/client/src/widgets/dialogs/note_attributes.css+++ b/apps/client/src/widgets/dialogs/note_attributes.css@@ -126,11 +126,12 @@ body.mobile .modal.note-attributes-modal {background: transparent;border-radius: 0;}- }- /* A menu item wraps its contents in a span, so the row's flex `gap` does not reach them. */- .attribute-row :is(.attribute-owner, .attribute-value) {- margin-inline-start: 6px;+ /* `!important` to outweigh the menus' hover fill (`.dropdown-item:hover` in+ theme-next/menus.css), which a touch screen leaves on the last row tapped. */+ .attribute-row.selected {+ background-color: var(--selection-background-color) !important;+ }}/* The help button beside the title in every card, whether or not an add button follows it. */diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex 1962393b74..ec5fc7b19d 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -79,7 +79,6 @@justify-content: center;}-.attribute-list-panel .attribute-row:hover .attribute-kind-check,.attribute-list-panel.selecting .attribute-kind-check {display: flex;}@@ -95,26 +94,31 @@cursor: pointer;}-/* The glyph the checkbox stands in for — badge and all, which would otherwise hang off its corner- saying something about an attribute that is not what the checkbox is asking. Hidden rather than- left out, so the slot keeps the width the icon gave it.-- Only where there is a checkbox to stand in for it, which is a pointer's rows: a phone marks a- picked row by turning its icon into a check (see AttributeRow), so its unpicked rows keep theirs- — and would otherwise be stripped of a badge that says the attribute is Trilium's own or its- field promoted, neither of which the picking is about. The wrapper holding the icon is what- these are about; on a phone the icon is itself `.attribute-kind`, hence the `.tn-icon` it always- carries telling the two apart. */-.attribute-list-panel .attribute-row:hover .attribute-kind:not(.tn-icon) > .tn-icon,-.attribute-list-panel.selecting .attribute-kind:not(.tn-icon) > .tn-icon {+/* The kind icon and its badge give way to the checkbox, hidden rather than removed so the slot keeps+ its width. */+.attribute-list-panel.selecting .attribute-kind:has(.attribute-kind-check) > .tn-icon {visibility: hidden;}-.attribute-list-panel .attribute-row:hover .attribute-kind:not(.tn-icon)::after,-.attribute-list-panel.selecting .attribute-kind:not(.tn-icon)::after {+.attribute-list-panel.selecting .attribute-kind:has(.attribute-kind-check)::after {display: none;}+/* A touch screen keeps `:hover` on the last row tapped. */+@media (hover: hover) {+ .attribute-list-panel .attribute-row:hover .attribute-kind-check {+ display: flex;+ }++ .attribute-list-panel .attribute-row:hover .attribute-kind:has(.attribute-kind-check) > .tn-icon {+ visibility: hidden;+ }++ .attribute-list-panel .attribute-row:hover .attribute-kind:has(.attribute-kind-check)::after {+ display: none;+ }+}+/* A fixed height, so that a selection starting or ending does not move the cards below. Sticky so thatit stays in view on a phone, where the whole sheet scrolls. */.attribute-toolbar {diff --git a/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsxindex 847cbea0b3..43c5bd9c47 100644--- a/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.mobile.spec.tsx@@ -144,11 +144,18 @@ describe("AttributeList on a phone", () => {act(() => void vi.advanceTimersByTime(600));expect(row?.className).toContain("selected");- // The mark a menu item is checked with, in the slot the kind icon holds — a phone has no- // checkbox to put there.- expect(row?.querySelector(".bx-check")).not.toBeNull();+ // The checkbox in the kind icon's slot, as on a desktop, ticked; nothing is added at the+ // row's end, so its layout stays as it was.+ expect(row?.querySelector<HTMLInputElement>(".attribute-kind-check input")?.checked).toBe(true);+ expect(row?.querySelector(".menu-trailing-icon")).toBeNull();expect(container.querySelector(".attribute-list-panel")?.className).toContain("selecting");+ // Once rows are being picked out, a tap anywhere on another row picks it too.+ const next = section("attributes").querySelectorAll<HTMLElement>(".attribute-row")[1];+ act(() => next.click());+ expect(next.className).toContain("selected");+ expect(next.querySelector<HTMLInputElement>(".attribute-kind-check input")?.checked).toBe(true);+// The toolbar above the cards turns over to the selection.expect(iconsIn(toolbar())).toEqual([ "bx bx-copy", "bx bx-trash", "bx bx-plus" ]);expect(toolbar()?.compareDocumentPosition(section("attributes")))diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex c511e1b9a8..540f7683b5 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -1078,8 +1078,7 @@ function AttributeRow({ attribute, note, active, valueEditor, isSystem, selected/*** A phone has no modifier to hold down, so it has the press itself held instead: held long enough,* it picks the row out rather than opening it, which is how a phone's lists are picked through.- * Once rows are being picked out a plain tap picks too — there being no checkbox to aim a thumb at- * on a row that is a menu item — which is the turn those lists take as well.+ * Once rows are being picked out a tap anywhere on the row picks too (see `selectFromRow`).*/useEffect(() => {const row = rowRef.current;@@ -1136,18 +1135,6 @@ function AttributeRow({ attribute, note, active, valueEditor, isSystem, selectedonSelect?.(e.shiftKey);}- // A menu item takes no capture handler of its own, so a phone's rows are bound theirs by hand.- useEffect(() => {- const row = rowRef.current;- if (!IS_MOBILE || !row || !selectsWholeRow) return;-- row.addEventListener("click", selectFromRow, true);- return () => row.removeEventListener("click", selectFromRow, true);- // The handler itself is left out: it is written anew on every render, where what it does- // turns only on the two below.- // eslint-disable-next-line react-hooks/exhaustive-deps- }, [ selectsWholeRow, onSelect ]);-function open(e: MouseEvent) {// Keep the container's closing handler from undoing this.e.stopPropagation();@@ -1234,38 +1221,21 @@ function AttributeRow({ attribute, note, active, valueEditor, isSystem, selected</>);- // On a phone the rows are menu items, drawn as everything else the note's menu leads to is: the- // panel is reached from that menu (see the note attributes modal), and a row there is something- // pressed with a thumb rather than pointed at.- if (IS_MOBILE) {- return (- <FormListItem- itemRef={rowRef}- className={rowClass}- icon={kindIcon}- // The badge hangs off the icon's own corner here, there being no wrapper to hang it on.- iconClassName={clsx("attribute-kind", markerClass)}- // A picked-out row takes the mark a menu item is checked with, in the slot its kind- // icon holds — the same trade the checkbox makes for itself on a desktop below.- checked={selected}- onClick={open}- >- {contents}- </FormListItem>- );- }-return (<liref={rowRef}- class={rowClass}+ // On a phone the row is dressed as a menu item, as the rest of what the note's menu leads+ // to is (see the note attributes modal).+ class={clsx(rowClass, IS_MOBILE && "dropdown-item")}onClickCapture={selectsWholeRow ? selectFromRow : undefined}onClick={open}- onContextMenu={onShowMenu}+ // A phone raises `contextmenu` on a long press, which selects the row instead.+ onContextMenu={IS_MOBILE ? undefined : onShowMenu}>{/* The icon is what carries the row's one tooltip: everything else about a row is already- written on it, and what the icon (badge and all) stands for is exactly what is not. */}- <span class={clsx("attribute-kind", markerClass)} title={kindTooltip}>+ written on it, and what the icon (badge and all) stands for is exactly what is not. A+ phone shows a tooltip only on a long press, which selects the row. */}+ <span class={clsx("attribute-kind", markerClass)} title={IS_MOBILE ? undefined : kindTooltip}><Icon icon={kindIcon} />{/* The way rows are picked out, standing in the kind icon's slot rather than taking a