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): leave the open-link button out of the in-place editor
Elian Doranfb05c6b22a01
diff --git a/apps/client/src/widgets/attribute_widgets/label_value_input.tsx b/apps/client/src/widgets/attribute_widgets/label_value_input.tsxindex 59f1359b85..794226e07e 100644--- a/apps/client/src/widgets/attribute_widgets/label_value_input.tsx+++ b/apps/client/src/widgets/attribute_widgets/label_value_input.tsx@@ -96,6 +96,12 @@ interface LabelValueInputProps {* text on its own, so a typo cannot slip into the shared definition.*/onCreateOption?: (option: string) => void | Promise<void>;+ /**+ * Leaves out the button opening a link-like value (a url as a page, an email or a phone number+ * through its scheme), for a host whose editor has no room to spare beside the field. Only that+ * button: a colour keeps its reset, without which an empty value could not be returned to.+ */+ hideOpenButton?: boolean;/** Merged onto the input, for the id, tab order and data attributes a host needs to attach. */inputProps?: InputHTMLAttributes<HTMLInputElement> & Record<`data-${string}`, string | undefined>;}@@ -108,7 +114,7 @@ interface LabelValueInputProps {* checkbox, which a host wanting the label after the box has to arrange itself.*/export default function LabelValueInput({- labelType, value, onCommit, commitOn = "input", numberPrecision, selectOptions, onCreateOption, inputProps+ labelType, value, onCommit, commitOn = "input", numberPrecision, selectOptions, onCreateOption, hideOpenButton, inputProps}: LabelValueInputProps) {const colorInputRef = useRef<HTMLInputElement>(null);// What has been typed but not yet committed is still what the field shows, so anything acting on@@ -138,7 +144,7 @@ export default function LabelValueInput({);}- const openButton = OPEN_BUTTONS[labelType];+ const openButton = hideOpenButton ? undefined : OPEN_BUTTONS[labelType];const extraProps: InputHTMLAttributes<HTMLInputElement> = {};if (labelType === "number" && numberPrecision) {diff --git a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx b/apps/client/src/widgets/sidebar/AttributeList.spec.tsxindex 15229b57cd..c106d67dac 100644--- a/apps/client/src/widgets/sidebar/AttributeList.spec.tsx+++ b/apps/client/src/widgets/sidebar/AttributeList.spec.tsx@@ -491,6 +491,20 @@ describe("AttributeList", () => {expect(archived?.querySelector(".attribute-value")?.textContent).toBe("");});+ it("leaves the open-link button out of the in-place editor, which has no room to spare for it", () => {+ renderPanel(buildNote({+ id: "linked", title: "Linked",+ "#site": "https://example.com",+ "#label:site": "promoted,single,url"+ }));++ act(() => firstRow().querySelector<HTMLElement>(".attribute-value")?.click());++ const editor = container.querySelector<HTMLElement>(".attribute-value-editor");+ expect(editor?.querySelector("input")?.type).toBe("url");+ expect(editor?.querySelector(".input-group-text")).toBeNull();+ });+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/AttributeValueEditor.tsx b/apps/client/src/widgets/sidebar/AttributeValueEditor.tsxindex 43936b1cb9..54ed246c68 100644--- a/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx+++ b/apps/client/src/widgets/sidebar/AttributeValueEditor.tsx@@ -126,6 +126,9 @@ export default function AttributeValueEditor({ note, attribute, onEdit, onCommitcommitOn="input"numberPrecision={typed.numberPrecision}selectOptions={typed.selectOptions}+ // The row has no room to spare beside the field for the button opening a+ // link-like value; the detail form keeps it, having the room.+ hideOpenButtoninputProps={{className: "form-control",// Names the dropdown's empty entry, as the detail form does for the same field.