Skip to content

Build your personal knowledge base with Trilium Notes

fix(promoted attributes): link the chips of a multi-valued relation

Elian Doran247de6ec262c
diff --git a/apps/client/src/widgets/attribute_widgets/relation_values_input.spec.tsx b/apps/client/src/widgets/attribute_widgets/relation_values_input.spec.tsx
index 5abb5ce54a..f7b6284f9c 100644
--- a/apps/client/src/widgets/attribute_widgets/relation_values_input.spec.tsx
+++ b/apps/client/src/widgets/attribute_widgets/relation_values_input.spec.tsx
@@ -46,7 +46,7 @@ describe("RelationValuesInput", () => {
return container;
}
- it("shows the targets as chips naming their notes, and drops the one pressed", async () => {
+ it("shows the targets as chips linking to their notes, and drops the one pressed", async () => {
const alpha = buildNote({ title: "Alpha" });
const beta = buildNote({ title: "Beta" });
const onCommit = vi.fn();
@@ -55,6 +55,15 @@ describe("RelationValuesInput", () => {
const chips = [ ...container.querySelectorAll(".tn-chip") ];
expect(chips.map((chip) => chip.textContent?.trim())).toEqual([ "Alpha", "Beta" ]);
+ // The title is the only way from the field to a target already held, so it opens the note:
+ // an anchor, which is what the global handler navigates on. The icon stays outside it, so
+ // the hover underline does not run across the gap between the two.
+ const links = chips.map((chip) => chip.querySelector("a.tn-link"));
+ expect(links.map((link) => link?.getAttribute("href")))
+ .toEqual([ `#root/${alpha.noteId}`, `#root/${beta.noteId}` ]);
+ expect(links[0]?.textContent).toBe("Alpha");
+ expect(links[0]?.querySelector(".tn-icon")).toBeNull();
+
await act(async () => chips[0]?.querySelector<HTMLElement>(".tn-chip-remove")?.click());
expect(onCommit).toHaveBeenCalledWith([ beta.noteId ]);
});
diff --git a/apps/client/src/widgets/attribute_widgets/relation_values_input.tsx b/apps/client/src/widgets/attribute_widgets/relation_values_input.tsx
index e55ee1a46d..d36c91e7e7 100644
--- a/apps/client/src/widgets/attribute_widgets/relation_values_input.tsx
+++ b/apps/client/src/widgets/attribute_widgets/relation_values_input.tsx
@@ -23,10 +23,10 @@ interface RelationValuesInputProps {
* The field a relation holding several targets is edited through: the targets as chips naming their
* notes, and after them the search box a single relation is already picked in.
*
- * A chip only names its note — icon and title — rather than linking to it: the field is for editing
- * the set, and a link inside it would carry a press meant for the chip off to the note instead. What
- * the box takes is a made choice, never text: a note has to be picked, so nothing typed is ever kept,
- * and a target already held is not taken a second time — the chips are a set.
+ * A chip names its note — icon and title — the title being a link opening it, the only way from
+ * here to a target already held; the button beside it removes the target. What the box takes is a
+ * made choice, never text: a note has to be picked, so nothing typed is ever kept, and a target
+ * already held is not taken a second time — the chips are a set.
*/
export default function RelationValuesInput({ values, onCommit, inputId, tabIndex, disabled }: RelationValuesInputProps) {
const inputRef = useRef<HTMLInputElement>(null);
@@ -66,7 +66,7 @@ export default function RelationValuesInput({ values, onCommit, inputId, tabInde
disabled={disabled}
onRemove={() => drop(noteId)}
>
- <span><NoteTitle note={notes[noteId]} /></span>
+ <span><NoteTitle note={notes[noteId]} linkTo={`#root/${noteId}`} /></span>
</Chip>
))}
<NoteAutocomplete
@@ -106,10 +106,17 @@ export function RelationValueChips({ values }: { values: readonly string[] }) {
/**
* A note as its chip names it: icon and title, or nothing while the note is still being fetched — a
* placeholder would only flash for the moment froca takes.
+ *
+ * `linkTo` is what the title opens, the icon and the space before it staying outside the link as
+ * `link.createLink` keeps them — the hover underline then runs under the words rather than across the
+ * gap to the icon.
*/
-function NoteTitle({ note }: { note: FNote | null | undefined }) {
+function NoteTitle({ note, linkTo }: { note: FNote | null | undefined; linkTo?: string }) {
if (!note) return null;
- return <><Icon icon={note.getIcon()} />{" "}{note.title}</>;
+ return <>
+ <Icon icon={note.getIcon()} />{" "}
+ {linkTo ? <a className="tn-link" href={linkTo}>{note.title}</a> : note.title}
+ </>;
}
/**
diff --git a/apps/client/src/widgets/react/Chip.css b/apps/client/src/widgets/react/Chip.css
index 2d6c128936..654c3cdd7d 100644
--- a/apps/client/src/widgets/react/Chip.css
+++ b/apps/client/src/widgets/react/Chip.css
@@ -117,6 +117,14 @@
}
}
+ a.tn-link {
+ --link-hover-background: transparent;
+ --link-hover-color: currentColor;
+
+ color: inherit;
+ font-weight: inherit;
+ }
+
/* Nothing to press where the set is read-only: the chips are then only a display of it, and a
button offering a removal that is not on the table would say otherwise. */
> .tn-chip-remove:disabled {