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): hold an empty label's slot open for the press it takes
Elian Dorane003b48585d7
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 3b643ff2b4..2c294408b2 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -814,6 +814,7 @@"delete_confirm": "Delete the attribute \"{{name}}\"?","add_definition": "Add a new definition","no_target": "No target note",+ "no_value": "No value","change_target": "Change the target note","inverse_of": "inverse of {{name}}","type_label": "Label",diff --git a/apps/client/src/widgets/sidebar/AttributeList.css b/apps/client/src/widgets/sidebar/AttributeList.cssindex 9deab99920..426656b70a 100644--- a/apps/client/src/widgets/sidebar/AttributeList.css+++ b/apps/client/src/widgets/sidebar/AttributeList.css@@ -108,6 +108,17 @@cursor: text;}+/* The placeholder holding an empty label's slot open. Hidden rather than left out, so the slot keeps+ the height the text gives it, and shown as the row's buttons are: over the row being pointed at,+ which is also the only row whose slot could be pressed. */+.attribute-list-panel .attribute-value.value-placeholder {+ visibility: hidden;+}++.attribute-list-panel .attribute-row:is(:hover, .active, .editing) .attribute-value.value-placeholder {+ visibility: visible;+}+/* A colour's chip keeps to its own size: a chip is laid out as a flex box, which alone in the value'sslot would run the width of it, a bar rather than a chip. */.attribute-list-panel .attribute-value > .label-color-chip {diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsxindex 47f6c555ac..15229b57cd 100644--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx@@ -468,6 +468,29 @@ describe("AttributeList", () => {expect(container.querySelector(".attribute-value-editor .note-autocomplete-stub")).not.toBeNull();});+ it("holds an empty label's slot open with a placeholder, which is the way into typing a value", () => {+ renderPanel(buildNote({ id: "bare-label", title: "Bare", "#todo": "" }));++ // The placeholder is what keeps the slot pressable at all: without text the row's centring+ // collapses the empty span to no height, and a press could never land on it. Its wording is+ // not asserted — translations stay unloaded here, as in every test of this file.+ const slot = firstRow().querySelector<HTMLElement>(".attribute-value");+ expect(slot?.className).toContain("value-placeholder");++ act(() => slot?.click());+ expect(container.querySelector<HTMLInputElement>(".attribute-value-editor input")).not.toBeNull();++ // A row the note cannot edit keeps its blank: its slot leads nowhere, so there is nothing to+ // hold open — and an inherited flag with no value is not something the note lacks.+ render(null, container);+ renderPanel(noteWithAttributes());+ const inherited = container.querySelector("#attributes-inherited");+ const archived = [ ...(inherited?.querySelectorAll(".attribute-row") ?? []) ]+ .find((row) => row.querySelector(".attribute-name")?.textContent === "archived");+ expect(archived?.querySelector(".attribute-value")?.className).not.toContain("value-placeholder");+ expect(archived?.querySelector(".attribute-value")?.textContent).toBe("");+ });+it("shows a colour label as the colour itself, and edits it through the picker", () => {renderPanel(buildNote({ id: "tinted", title: "Tinted", "#color": "#8000ff" }));diff --git a/apps/client/src/widgets/sidebar/AttributeList.tsx b/apps/client/src/widgets/sidebar/AttributeList.tsxindex c5434fa107..48d087cd65 100644--- a/apps/client/src/widgets/sidebar/AttributeList.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.tsx@@ -705,19 +705,28 @@ function AttributeValue({ attribute, note, attrType, onEdit }: {// still shows the chip, as the empty ring it draws: unset is an answer a colour field can give.const isColor = note && resolveValueField(note, attribute.name).labelType === "color";+ // An editable slot holding nothing gets a placeholder instead of the blank: the row centres its+ // items, which collapses an empty span to a height of nothing — width but no height, a click+ // target that cannot be hit. The placeholder holds the slot open and names the way in, though only+ // over the row being pointed at (see the stylesheet): many a bare label is a flag meaning what its+ // presence means, and a standing "no value" against every one of them would read as a lack.+ const placeholder = !isColor && !attribute.value && onEdit;+// A label with no value still gets its slot: it is what takes up the room between the name and what// the row ends with, so a bare label lines its markers and its delete button up with every other row's.return (<span- class={clsx("attribute-value", onEdit && "editable")}- title={isColor ? undefined : attribute.value}+ class={clsx("attribute-value", onEdit && "editable", placeholder && "empty value-placeholder")}+ title={isColor || placeholder ? undefined : attribute.value}// Kept from the row, which would open the popup over the field this press asks for.onClick={onEdit ? (e) => {e.stopPropagation();onEdit();} : undefined}>- {isColor ? <ColorChip color={attribute.value ?? ""} /> : attribute.value}+ {isColor ? <ColorChip color={attribute.value ?? ""} />+ : placeholder ? t("attribute_list_panel.no_value")+ : attribute.value}</span>);}