Skip to content

Build your personal knowledge base with Trilium Notes

Fix the merge fallout and the picker's note prop

BeatLinkd8d878a43503
diff --git a/CLAUDE.md b/CLAUDE.md
index ee723232d9..7111fbfcb0 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -129,7 +129,7 @@ Common UI components are available in `apps/client/src/widgets/react/` — **alw
- `Slider` - Range slider with label
- `Checkbox`, `RadioButton` - Form controls
- `Collapsible` - Expandable content section (animated, theme-styled); `ExternallyControlledCollapsible` is the controlled variant (caller owns `expanded`/`setExpanded`) vs. `Collapsible`'s self-managed `initiallyExpanded`
-- `ColorPicker` - Color picker combining preset swatches with the browser's native `<input type="color">`; value is a CSS color string (`onChange(null)` clears). A controlled, flat swatch row — wrap it in a `Dropdown` to get a popover, or use it inline; don't hand-roll a color palette from scratch
+- `ColorPicker` - Color picker combining preset swatches with the browser's native `<input type="color">`; value is a CSS color string (`onChange(null)` clears). A controlled, flat swatch row — wrap it in a `Dropdown` to get a popover, or use it inline; don't hand-roll a color palette from scratch. `NoteColorPicker` is the note-bound variant that reads/writes the note's `color` label
- `Badge` - Colored pill/label with optional icon, tooltip, and `onClick` (for counts, status flags). Set its color via the `--color` CSS variable on a wrapper class (not inline styles); pass `outline` for a colored-border/transparent-fill variant instead of a solid background. `BadgeWithDropdown` pairs a badge with a dropdown menu. Don't hand-roll pill/badge markup — reuse it
- `Table` - Generic [Tabulator](https://tabulator.info/)-based data grid (`columns`, `data`, `events`, `modules`, `tabulatorRef`; props typed via `TableProps<T>`). Decoupled from the note/collection model — deals purely in columns/data/events, so use it for any grid (e.g. the SQL console results, the note collection table view). Prefer it over instantiating `tabulator-tables` directly
- `Calendar` - Generic [FullCalendar](https://fullcalendar.io/) wrapper (accepts any `CalendarOptions` plus a `calendarRef`; props typed via `CalendarProps`). Decoupled from the note/collection model — deals purely in FullCalendar options, so use it for any calendar rather than instantiating `@fullcalendar/core` directly
diff --git a/apps/client/src/menus/custom-items/NoteColorPicker.spec.tsx b/apps/client/src/menus/custom-items/NoteColorPicker.spec.tsx
index 4dc52cd5dd..118553153f 100644
--- a/apps/client/src/menus/custom-items/NoteColorPicker.spec.tsx
+++ b/apps/client/src/menus/custom-items/NoteColorPicker.spec.tsx
@@ -1,4 +1,4 @@
-import { ComponentChild } from "preact";
+import { ComponentChild, render } from "preact";
import { act } from "preact/test-utils";
import { beforeEach, describe, expect, it, vi } from "vitest";
@@ -309,6 +309,31 @@ describe("NoteColorPicker", () => {
expect(removeOwnedLabelByNameMock).not.toHaveBeenCalled();
});
+ it("picks up a note that arrives after the first render", async () => {
+ // A parent that mounts with `note={null}` while it loads and supplies the note afterwards
+ // must end up with an enabled picker: the note-resolving effect has to re-run on the prop
+ // change rather than only on mount.
+ const note = buildNote({ title: "Late arrival", "#color": DEFAULT_COLOR_PALETTE[2] });
+ let container: HTMLElement | undefined;
+
+ await act(async () => {
+ container = renderInto(<NoteColorPicker note={null} />);
+ });
+ expect(container!.innerHTML).toBe("");
+
+ // Re-render into the same container so Preact updates the existing component instance
+ // (a fresh `renderInto` would mount a brand new one and hide the bug).
+ await act(async () => {
+ render(<NoteColorPicker note={note} />, container!);
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ });
+
+ expect(cells(container!).some((cell) => cell.classList.contains("disabled-color-cell"))).toBe(false);
+ const selected = presetCells(container!).filter((cell) => cell.classList.contains("selected"));
+ expect(selected).toHaveLength(1);
+ expect(selected[0].getAttribute("style")).toContain(DEFAULT_COLOR_PALETTE[2]);
+ });
+
it("removes the colour label when the colour is cleared", async () => {
const note = buildNote({ title: "Clearable", "#color": DEFAULT_COLOR_PALETTE[0] });
diff --git a/apps/client/src/menus/custom-items/NoteColorPicker.tsx b/apps/client/src/menus/custom-items/NoteColorPicker.tsx
index 2344d40a2e..50298ec69b 100644
--- a/apps/client/src/menus/custom-items/NoteColorPicker.tsx
+++ b/apps/client/src/menus/custom-items/NoteColorPicker.tsx
@@ -38,7 +38,7 @@ export default function NoteColorPicker(props: NoteColorPickerProps) {
} else {
setNote(props.note);
}
- }, []);
+ }, [props.note]);
useEffect(() => {
setCurrentColor(note?.getLabel("color")?.value ?? null);
diff --git a/apps/client/src/widgets/PromotedAttributes.spec.tsx b/apps/client/src/widgets/PromotedAttributes.spec.tsx
index 9547974e67..4ce4a90211 100644
--- a/apps/client/src/widgets/PromotedAttributes.spec.tsx
+++ b/apps/client/src/widgets/PromotedAttributes.spec.tsx
@@ -200,10 +200,12 @@ describe("PromotedAttributesContent", () => {
]);
expect(twoDecimals.querySelector("input.promoted-attribute-input")?.getAttribute("step")).toBe("0.01");
+ // With no precision declared the field is left to the browser's default stepping rather
+ // than being pinned to a step of its own.
const noPrecision = await renderCells(note, [
buildCell(note, { definition: { labelType: "number" }, uniqueId: "no-precision" })
]);
- expect(noPrecision.querySelector("input.promoted-attribute-input")?.getAttribute("step")).toBe("1");
+ expect(noPrecision.querySelector("input.promoted-attribute-input")?.getAttribute("step")).toBeNull();
});
it("moves the label after the checkbox for boolean attributes and reflects the checked state", async () => {
@@ -247,10 +249,16 @@ describe("PromotedAttributesContent", () => {
openButton?.click();
expect(windowOpen).toHaveBeenCalledWith("https://example.com", "_blank");
- // An empty value must not open a blank tab.
- windowOpen.mockClear();
- if (input) input.value = "";
- openButton?.click();
+ windowOpen.mockRestore();
+ });
+
+ it("does not open a blank tab for a url attribute with no value", async () => {
+ const container = await renderCells(note, [
+ buildCell(note, { definition: { labelType: "url" }, value: "", uniqueId: "empty-url" })
+ ]);
+
+ const windowOpen = vi.spyOn(window, "open").mockImplementation(() => null);
+ container.querySelector<HTMLElement>(".open-external-link-button")?.click();
expect(windowOpen).not.toHaveBeenCalled();
windowOpen.mockRestore();
});
diff --git a/apps/client/src/widgets/PromotedAttributes.tsx b/apps/client/src/widgets/PromotedAttributes.tsx
index 647b383254..ff46180029 100644
--- a/apps/client/src/widgets/PromotedAttributes.tsx
+++ b/apps/client/src/widgets/PromotedAttributes.tsx
@@ -2,7 +2,6 @@ import "./PromotedAttributes.css";
import { DefinitionObject, extractAttributeDefinitionTypeAndName, UpdateAttributeResponse } from "@triliumnext/commons";
import clsx from "clsx";
-import { ComponentChild, createElement, HTMLInputTypeAttribute, InputHTMLAttributes, MouseEventHandler, TargetedEvent } from "preact";
import { ComponentChild, MouseEventHandler, TargetedEvent } from "preact";
import { Dispatch, StateUpdater, useCallback, useEffect, useState } from "preact/hooks";
@@ -223,31 +222,15 @@ function LabelInput(props: CellProps & { inputId: string }) {
}
return (
<div className="input-group">
- {inputNode}
+ {input}
{ definition.labelType === "color" && (
<ColorPicker
currentValue={valueAttr.value || null}
onChange={(color) => updateAttribute(note, cell, componentId, color ?? "", setCells)}
/>
)}
- { definition.labelType === "url" && (
- <InputButton
- className="open-external-link-button"
- icon="bx bx-window-open"
- title={t("promoted_attributes.open_external_link")}
- onClick={(e) => {
- const inputEl = document.getElementById(inputId) as HTMLInputElement | null;
- const url = inputEl?.value;
- if (url) {
- window.open(url, "_blank");
- }
- }}
- />
- )}
</div>
);
-
- return <div className="input-group">{input}</div>;
}