Skip to content

Build your personal knowledge base with Trilium Notes

feat(collections/table): show a flag cell as a checkbox

Elian Doran149c9b44bd11
diff --git a/apps/client/src/widgets/collections/table/columns.css b/apps/client/src/widgets/collections/table/columns.css
index eab000dfa1..e3505f2546 100644
--- a/apps/client/src/widgets/collections/table/columns.css
+++ b/apps/client/src/widgets/collections/table/columns.css
@@ -111,6 +111,15 @@
}
}
+.tabulator-cell label.table-flag-checkbox {
+ --box-label-gap: 0;
+
+ display: inline-block;
+ height: var(--box-size, 1em);
+ vertical-align: middle;
+ pointer-events: none;
+}
+
.tabulator-cell:not(.tabulator-editable) {
.table-open-note {
display: none;
diff --git a/apps/client/src/widgets/collections/table/columns.spec.ts b/apps/client/src/widgets/collections/table/columns.spec.ts
index 0ac8608592..5d5b8f0883 100644
--- a/apps/client/src/widgets/collections/table/columns.spec.ts
+++ b/apps/client/src/widgets/collections/table/columns.spec.ts
@@ -253,7 +253,7 @@ describe("buildColumnDefinitions — typed columns", () => {
expect(url({ getValue: () => "https://example.com" } as CellComponent)).toBe("https://example.com");
});
- it("shows a single flag as the chip a set of flags wears, and an unset one as false", () => {
+ it("shows a single flag as a checkbox, ticked only when the flag is true", () => {
const [ column ] = buildColumnDefinitions({
info: [ { name: "done", type: "boolean" } ],
movableRows: false,
@@ -266,17 +266,25 @@ describe("buildColumnDefinitions — typed columns", () => {
const format = (value: unknown) =>
formatter({ getValue: () => value } as CellComponent, {}, () => {}) as HTMLElement;
+ const checkboxOf = (value: unknown) => {
+ const element = format(value);
+ const checkbox = element.querySelector<HTMLInputElement>("label.tn-checkbox > input[type=checkbox]");
+ if (!checkbox) throw new Error("expected a checkbox in a tn-checkbox label");
+ expect(element.querySelector(".tn-chip")).toBeNull();
+ return checkbox;
+ };
+
// A stored label holds the text "true", a value fresh from the tickCross editor a real
- // boolean; either reads as the one chip, washed with its answer.
+ // boolean.
for (const set of [ "true", true ]) {
- expect(format(set).querySelector(".tn-chip")?.className).toContain("label-flag-chip-set");
- expect(format(set).querySelector(".tn-icon")?.getAttribute("title")).toBe("true");
+ expect(checkboxOf(set).checked).toBe(true);
}
// A note without the label reads as false, as the promoted checkbox shows it unticked.
for (const unset of [ "false", false, "", undefined, null ]) {
- expect(format(unset).querySelector(".tn-chip")?.className).toContain("label-flag-chip-unset");
- expect(format(unset).querySelector(".tn-icon")?.getAttribute("title")).toBe("false");
+ expect(checkboxOf(unset).checked).toBe(false);
}
+ // The cell's editor does the toggling, so the box stays out of the tab order.
+ expect(checkboxOf(true).tabIndex).toBe(-1);
});
});
diff --git a/apps/client/src/widgets/collections/table/columns.tsx b/apps/client/src/widgets/collections/table/columns.tsx
index ba637d5ec5..7c21d3e02a 100644
--- a/apps/client/src/widgets/collections/table/columns.tsx
+++ b/apps/client/src/widgets/collections/table/columns.tsx
@@ -57,8 +57,7 @@ const labelTypeMappings: Record<ColumnType, Partial<ColumnDefinition>> = {
editor: wrapEditor(SelectEditor)
},
boolean: {
- // The same chip a set of flags wears, one chip for the one value, so a column of flags
- // reads the same whether each note holds one or several. Toggling stays Tabulator's own.
+ // A checkbox, as the promoted field shows the flag. Toggling stays Tabulator's own.
formatter: wrapFormatter(FlagFormatter),
editor: "tickCross",
// Values arrive as strings ("true"/"false") from stored labels but as real booleans
@@ -636,15 +635,20 @@ function ColorFormatter({ cell }: FormatterOpts) {
return <LabelValueChips values={[ color ]} labelType="color" />;
}
-/** A flag cell as the chip a set of flags shows, with an unset cell holding no chip at all. */
+/** A flag cell as a checkbox, unticked for a note without the label. */
function FlagFormatter({ cell }: FormatterOpts) {
const value = cell.getValue();
// A stored label arrives as the text "true"/"false", but one just toggled through the tickCross
// editor is a real boolean. A note without the label reads as false, as the promoted checkbox
// shows it unticked.
- const flag = value === true || value === "true" ? "true" : "false";
+ const isSet = value === true || value === "true";
- return <LabelValueChips values={[ flag ]} labelType="boolean" />;
+ // Display only: `table.css` lets clicks through to the cell, which opens the `tickCross` editor.
+ return (
+ <label className="tn-checkbox table-flag-checkbox">
+ <input type="checkbox" checked={isSet} tabIndex={-1} aria-readonly="true" />
+ </label>
+ );
}
/**