Skip to content

Build your personal knowledge base with Trilium Notes

fix(table): tell the box a value is entered in from the values already taken

Elian Doran8677d61c1cd3
diff --git a/apps/client/src/widgets/attribute_widgets/values_input.css b/apps/client/src/widgets/attribute_widgets/values_input.css
index 23fa09490e..db56dbc48f 100644
--- a/apps/client/src/widgets/attribute_widgets/values_input.css
+++ b/apps/client/src/widgets/attribute_widgets/values_input.css
@@ -3,7 +3,7 @@
* no room to type in: it sits at its own size beside the chips instead of taking the line a text box
* would, and keeps a frame of its own — a swatch with nothing around it would read as another chip.
*/
-.values-input > input[type="color"].form-control {
+.values-input input[type="color"].form-control {
flex: 0 0 auto;
/* Cleared as well as set: the field gives a box room to type in, which a picker would otherwise
hold on to — it is the wider of the two that decides. */
@@ -16,19 +16,14 @@
/*
* A field whose values are entered through a widget the browser brings: a calendar, a clock, a colour
- * dialog. Each asks for about the width of the field itself, so a chip sharing the line with one
- * would be squeezed to nothing — the values stack above it instead, a line each, and the widget waits
- * at the foot of them.
+ * dialog. Each asks for about the width of the field itself, so a value sharing the line with one
+ * would be squeezed to nothing — the values take a line each instead, under the widget.
*/
.values-input.stacked {
flex-direction: column;
- align-items: stretch;
-
- /* Held to their content's height, a column stretching them to fill the field otherwise. */
- > .tn-chip,
- > .form-control {
- flex: 0 0 auto;
- }
+ /* Each value only as wide as the word on it: stretched to the field, one would read as a row of
+ the table rather than as one of several held in a cell. */
+ align-items: flex-start;
/*
* The widget leads and the values follow, rather than the other way about. Not for the reading of
@@ -37,21 +32,24 @@
* the rows scroll in, and scrolling that hands the row being edited back to be rendered afresh,
* editor and all. Kept at the head, it does not move, and nothing is scrolled.
*/
- > .form-control {
+ > .values-input-entry {
order: -1;
- align-self: flex-start;
+ display: flex;
+ align-items: center;
+ gap: 4px;
}
- /* Beside the widget it belongs to, which is now the first line rather than the last. */
- > .values-input-add {
- position: absolute;
- inset-block-start: 4px;
- inset-inline-end: 4px;
+ /*
+ * The box a value is entered into, told apart from the values already taken. Those are chips lying
+ * on the field's own surface, so a box with neither edge nor ground of its own reads as a gap
+ * between them rather than as somewhere to type — the more so for a widget, which draws only its
+ * own placeholder until something is entered.
+ */
+ .form-control:not([type="color"]) {
+ flex: 0 1 auto;
+ background-color: var(--input-background-color);
+ border: 1px solid var(--main-border-color);
+ border-radius: var(--badge-radius, 12px);
+ padding-inline: 8px;
}
}
-
-/* Made room for, so that a wide widget does not run under the button that takes its value. */
-.values-input.stacked:has(> .values-input-add) {
- position: relative;
- padding-inline-end: 28px;
-}
diff --git a/apps/client/src/widgets/attribute_widgets/values_input.tsx b/apps/client/src/widgets/attribute_widgets/values_input.tsx
index ee890eee09..0fa7c32b6f 100644
--- a/apps/client/src/widgets/attribute_widgets/values_input.tsx
+++ b/apps/client/src/widgets/attribute_widgets/values_input.tsx
@@ -115,9 +115,14 @@ export default function ValuesInput({ labelType, values, onCommit, renderValue,
<span>{renderValue ? renderValue(value) : value}</span>
</Chip>
))}
- {/* Keyed, as the chips before them are: a field of keyed and unkeyed siblings together
- is matched up by position as it grows, so taking a second value would rebuild the box
+ {/* The box and the button that asks for what it holds are one thing on the page, so where
+ the values are stacked they are wrapped as one — the alternative, laying the button
+ over the field, puts it on whatever the widget's own width happens to reach.
+
+ Keyed, as the chips before them are: a field of keyed and unkeyed siblings together is
+ matched up by position as it grows, so taking a second value would rebuild the box
rather than keep it — losing the focus in it, and with it the widget it had open. */}
+ <Entry stacked={PICKED_TYPES.has(labelType)}>
{isColor ? (
<input
key="field"
@@ -156,6 +161,7 @@ export default function ValuesInput({ labelType, values, onCommit, renderValue,
onClick={() => take(inputRef.current?.value ?? "")}
/>
)}
+ </Entry>
</div>
);
}
@@ -165,3 +171,12 @@ export default function ValuesInput({ labelType, values, onCommit, renderValue,
* rather than by typing into a box.
*/
const PICKED_TYPES = new Set<LabelType>([ "color", "date", "datetime", "time" ]);
+
+/**
+ * The box and the button beside it, held together where the values above them are stacked a line
+ * each — a column would otherwise put the button on a line of its own. Where they share the line with
+ * the values there is nothing to hold: they are already side by side.
+ */
+function Entry({ stacked, children }: { stacked: boolean; children: ComponentChildren }) {
+ return stacked ? <div className="values-input-entry">{children}</div> : <>{children}</>;
+}