Skip to content

Build your personal knowledge base with Trilium Notes

style(attributes): draw a selected row as the note tree draws one

Elian Doran6d4d5e5f1591
diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.css
index 356c38a78f..4d3694e05f 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.css
+++ b/apps/client/src/widgets/sidebar/AttributeList.css
@@ -42,23 +42,9 @@
background-color: var(--hover-item-background-color);
}
-/* Picked out to be copied. Held apart from the row merely being pointed at or shown in the popup —
- which come and go with the pointer — by the standing mark of a filled leading edge, and by a
- ground that outweighs the hover film so a picked row pointed at still reads as picked. */
.attribute-list-panel .attribute-row.selected,
.attribute-list-panel .attribute-row.selected:hover {
- background-color: var(--active-item-background-color);
-}
-
-.attribute-list-panel .attribute-row.selected::before {
- content: "";
- position: absolute;
- inset-block: 2px;
- inset-inline-start: 0;
- width: 2px;
- border-radius: 1px;
- background-color: var(--main-text-color);
- opacity: 0.5;
+ background-color: var(--selection-background-color);
}
/* While its value is edited (or the attribute created), the row lets the editor standing over it
@@ -88,10 +74,13 @@
display: flex;
}
-.attribute-list-panel .attribute-kind-check .form-check-input {
- /* The icon's own size, so that the row is laid out the same whichever of the two is showing. */
- width: 13px;
- height: 13px;
+.attribute-list-panel .attribute-kind-check .tn-checkbox {
+ --box-size: 13px;
+ --box-label-gap: 0px;
+
+ display: block;
+ width: var(--box-size);
+ height: var(--box-size);
margin: 0;
cursor: pointer;
}
diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
index 1279036805..a87c157d67 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx
@@ -1102,19 +1102,19 @@ describe("AttributeList", () => {
expect(selectedNames()).toEqual([ "template" ]);
// The theme draws the box on the label, over the input, so that is where a press lands. A
- // browser would pass it on to the input as a second click, after re-rendering, which toggled
- // the row straight back; the label's press is the only one.
- const part = (selector: string) =>
- container.querySelectorAll(".attribute-kind-check")[1]?.querySelector<HTMLElement>(selector);
- expect(part("label")).not.toBeNull();
- const inputClicks = vi.fn();
- part("input")?.addEventListener("click", inputClicks);
-
- act(() => part("label")?.click());
- expect(selectedNames()).toEqual([ "cssClass", "template" ]);
- act(() => part("label")?.click());
- expect(selectedNames()).toEqual([ "template" ]);
- expect(inputClicks).not.toHaveBeenCalled();
+ // browser passes an uncancelled label click on to the input after re-rendering, and that
+ // second click toggled the row straight back. happy-dom passes it on before the click
+ // bubbles, so the cancellation is what is asserted.
+ const label = () => container.querySelectorAll(".attribute-kind-check")[1]?.querySelector("label");
+ for (const expected of [ [ "cssClass", "template" ], [ "template" ] ]) {
+ const press = new MouseEvent("click", { bubbles: true, cancelable: true });
+ expect(label()).not.toBeNull();
+ act(() => {
+ label()?.dispatchEvent(press);
+ });
+ expect(press.defaultPrevented).toBe(true);
+ expect(selectedNames()).toEqual(expected);
+ }
});
it("turns the toolbar over to the selected rows, keeping paste and add where they were", async () => {
diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsx
index 3a8a85f293..045114f620 100644
--- a/apps/client/src/widgets/sidebar/AttributeList.tsx
+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx
@@ -1255,17 +1255,23 @@ function AttributeRow({ attribute, note, active, valueEditor, isSystem, selected
class="attribute-kind-check"
onClick={(e) => {
// Kept from the row, whose press would open the form over the selection.
- // The tick itself is left to the browser: refusing it puts the box back
- // after this handler has run, leaving it a press behind the selection it
- // is drawn from. What the press means either way is the same, so the two
- // agree — and the box is drawn from the selection on every render after.
e.stopPropagation();
+ // The label's `::after` covers the input, so presses land on the label. Its
+ // default action clicks the input a second time, after a re-render, which
+ // would toggle the row back. `checked` follows the selection either way.
+ // A press on the input itself keeps its default: cancelling a checkbox's
+ // click reverts its tick after this handler runs.
+ if (e.target instanceof HTMLLabelElement) {
+ e.preventDefault();
+ }
onSelect(e.shiftKey);
}}
>
- {/* Not the form's checkbox component: that one is a labelled row of a settings
- page, where this is the glyph of an icon's slot. */}
- <input type="checkbox" class="form-check-input" checked={selected} tabIndex={-1} />
+ {/* The theme's checkbox (`label.tn-checkbox`) without `FormCheckbox`'s label
+ text, which the icon slot has no room for. */}
+ <label class="tn-checkbox">
+ <input type="checkbox" checked={selected} tabIndex={-1} />
+ </label>
</span>
)}
</span>