Skip to content

Build your personal knowledge base with Trilium Notes

feat(attributes): enter select options as chips

Elian Doran59ae81dbed65
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 12b2d1138e..2876249908 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -549,7 +549,6 @@
"select_type": "Select",
"select_options": "Options",
"select_options_title": "The options the field offers, in this order.",
- "add_option": "Add option",
"remove_option": "Remove this option",
"precision_title": "Max number of decimal places.",
"precision": "Precision",
diff --git a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
index 6102b7f68a..28b8d03de3 100644
--- a/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
+++ b/apps/client/src/widgets/attribute_widgets/attribute_detail.tsx
@@ -24,7 +24,6 @@ import FormAutocomplete, { AUTOCOMPLETE_DROPDOWN_SELECTOR } from "../react/FormA
import FormDropdownList from "../react/FormDropdownList.jsx";
import { FormDropdownDivider, FormListItem } from "../react/FormList.jsx";
import FormTextBox, { FormTextBoxWithUnit } from "../react/FormTextBox.jsx";
-import FormTextBoxList from "../react/FormTextBoxList.jsx";
import HelpTooltipButton from "../react/HelpTooltipButton.jsx";
import { suspendModalFocusTraps } from "../react/modal_focustrap.js";
import NoteAutocomplete from "../react/NoteAutocomplete.jsx";
@@ -33,6 +32,7 @@ import { disposeReactWidget, ParentComponent, renderReactWidgetAtElement } from
import OptionsRow, { OptionsRowWithToggle } from "../type_widgets/options/components/OptionsRow.jsx";
import { ATTR_HELP, AttrHelpEntry } from "./attr_help.js";
import LabelValueInput, { getTypedInputForLabel } from "./label_value_input.js";
+import ValuesInput from "./values_input.jsx";
export interface AttributeDetailOpts {
allAttributes?: Attribute[];
@@ -633,15 +633,15 @@ export function AttributeForm({ opts, attrType: initialAttrType, currentNoteId,
label={t("attribute_detail.select_options")}
description={t("attribute_detail.select_options_title")}
>
- {/* The draft rows need no synchronizing back from the definition: the form
- remounts per show (see above), so they are seeded once, like the fields
- around them. */}
- <FormTextBoxList
- initialValues={definition.selectOptions ?? []}
+ {/* The same chips the values themselves are edited through elsewhere, only
+ typed free: the options are being invented here, so there is nothing to
+ offer or pick from. */}
+ <ValuesInput
+ labelType="text"
+ values={definition.selectOptions ?? []}
disabled={!isOwned}
- addButtonText={t("attribute_detail.add_option")}
removeButtonText={t("attribute_detail.remove_option")}
- onChange={(selectOptions) => commitDefinition({ selectOptions })}
+ onCommit={(selectOptions) => commitDefinition({ selectOptions })}
/>
</OptionsRow>
)}
diff --git a/apps/client/src/widgets/attribute_widgets/values_input.tsx b/apps/client/src/widgets/attribute_widgets/values_input.tsx
index 0fa7c32b6f..3f21590f97 100644
--- a/apps/client/src/widgets/attribute_widgets/values_input.tsx
+++ b/apps/client/src/widgets/attribute_widgets/values_input.tsx
@@ -23,6 +23,10 @@ interface ValuesInputProps {
* out, a chip reads as what is stored, which for most types is what is being edited anyway.
*/
renderValue?(value: string): ComponentChildren;
+ /** What removing a chip means, in the host's own words. Left out, a chip holds "a value". */
+ removeButtonText?: string;
+ /** Set onto the box, so that a host's own label points at the field. */
+ inputId?: string;
placeholder?: string;
disabled?: boolean;
}
@@ -36,7 +40,7 @@ interface ValuesInputProps {
* rather than quietly dropped. A value already held is not taken a second time: the chips are a set,
* and two alike could not be told apart.
*/
-export default function ValuesInput({ labelType, values, onCommit, renderValue, placeholder, disabled }: ValuesInputProps) {
+export default function ValuesInput({ labelType, values, onCommit, renderValue, removeButtonText, inputId, placeholder, disabled }: ValuesInputProps) {
const [ draft, setDraft ] = useState("");
const inputRef = useRef<HTMLInputElement>(null);
const isColor = labelType === "color";
@@ -108,7 +112,7 @@ export default function ValuesInput({ labelType, values, onCommit, renderValue,
{values.map((value) => (
<Chip
key={value}
- removeButtonText={t("promoted_attributes.remove_value")}
+ removeButtonText={removeButtonText ?? t("promoted_attributes.remove_value")}
disabled={disabled}
onRemove={() => drop(value)}
>
@@ -127,6 +131,7 @@ export default function ValuesInput({ labelType, values, onCommit, renderValue,
<input
key="field"
ref={inputRef}
+ id={inputId}
className="form-control"
type="color"
disabled={disabled}
@@ -135,6 +140,7 @@ export default function ValuesInput({ labelType, values, onCommit, renderValue,
<FormTextBox
key="field"
inputRef={inputRef}
+ id={inputId}
type={LABEL_MAPPINGS[labelType] ?? "text"}
currentValue={draft}
// Only while the field is empty: beside chips it would read as one of them.