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
feat(promoted_attributes): support removing color
Elian Dorand23230df68be
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 13f9258e04..7fd0bc7003 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -841,7 +841,8 @@"unknown_label_type": "Unknown label type '{{type}}'","unknown_attribute_type": "Unknown attribute type '{{type}}'","add_new_attribute": "Add new attribute",- "remove_this_attribute": "Remove this attribute"+ "remove_this_attribute": "Remove this attribute",+ "remove_color": "Remove the color label"},"script_executor": {"query": "Query",diff --git a/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts b/apps/client/src/widgets/ribbon_widgets/promoted_attributes.tsindex 5f21cb6e5f..e843edb586 100644--- a/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts+++ b/apps/client/src/widgets/ribbon_widgets/promoted_attributes.ts@@ -272,7 +272,29 @@ export default class PromotedAttributesWidget extends NoteContextAwareWidget {$input.after($openButton);} else if (definition.labelType === "color") {- $input.prop("type", "color");+ $input.prop("type", "hidden");+ const setValue = (color: string, event: JQuery.TriggeredEvent<HTMLElement, undefined, HTMLElement, HTMLElement>) => {+ $input.val(color);++ event.target = $input[0]; // Set the event target to the main input+ this.promotedAttributeChanged(event);+ };++ // We insert a separate input since the color input does not support empty value.+ // This is a workaround to allow clearing the color input.+ const $colorInput = $("<input>")+ .prop("type", "color")+ .prop("value", valueAttr.value ?? "#000000")+ .addClass("form-control promoted-attribute-input")+ .on("change", e => setValue((e.target as HTMLInputElement).value, e));+ $input.after($colorInput);++ const $clearButton = $("<span>")+ .addClass("input-group-text bx bxs-tag-x")+ .prop("title", t("promoted_attributes.remove_color"))+ .on("click", e => setValue("", e));++ $colorInput.after($clearButton);} else {ws.logError(t("promoted_attributes.unknown_label_type", { type: definition.labelType }));}