Skip to content

Build your personal knowledge base with Trilium Notes

fix(text): open the picker for a text's custom color

Elian Doran42d108b18445
diff --git a/apps/client/src/widgets/react/ColorPicker.tsx b/apps/client/src/widgets/react/ColorPicker.tsx
index 59ecec3104..b356cfc238 100644
--- a/apps/client/src/widgets/react/ColorPicker.tsx
+++ b/apps/client/src/widgets/react/ColorPicker.tsx
@@ -180,12 +180,14 @@ function CustomColorCell(props: ColorCellProps) {
}, [props.onSelect]);
const onSelect = useCallback(() => {
- if (pickedColor !== null) {
+ // A selected cell already holds the color. Reporting it again lets a menu close and
+ // unmount the input before its picker opens.
+ if (pickedColor !== null && !props.isSelected) {
callbackRef.current?.(pickedColor);
}
colorInput.current?.click();
- }, [pickedColor]);
+ }, [pickedColor, props.isSelected]);
return <div style={`--foreground: ${getForegroundColor(props.color)};`}
onClick={(e) => {
diff --git a/apps/client/src/widgets/type_widgets/text/color_menu.spec.tsx b/apps/client/src/widgets/type_widgets/text/color_menu.spec.tsx
index 41c9fe2bbb..2027d7bef7 100644
--- a/apps/client/src/widgets/type_widgets/text/color_menu.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/text/color_menu.spec.tsx
@@ -57,6 +57,23 @@ describe("createColorMenuHost", () => {
expect(second.setColor).toHaveBeenCalledExactlyOnceWith("fontColor", null);
});
+ it("opens the picker from the custom cell holding the color of the text, keeping the menu", async () => {
+ const pick = vi.spyOn(HTMLInputElement.prototype, "click").mockImplementation(() => {});
+ try {
+ const { menu, pickers, setColor } = show({ fontColor: "#123456", fontBackgroundColor: null });
+ const cell = pickers[0]?.querySelector<HTMLElement>(".custom-color-cell.selected");
+ if (!cell) throw new Error("expected the custom cell to be selected");
+ await vi.waitFor(() => expect(cell.style.getPropertyValue("--color")).toBe("#123456"));
+ cell.click();
+
+ expect(setColor).not.toHaveBeenCalled();
+ expect(menu.isConnected).toBe(true);
+ expect(pick.mock.contexts).toEqual([ cell.querySelector("input[type=color]") ]);
+ } finally {
+ pick.mockRestore();
+ }
+ });
+
it("returns focus to the button on Escape, and not on a press elsewhere", () => {
const escaped = show({ fontColor: null, fontBackgroundColor: null });
escaped.menu.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));