Skip to content

Build your personal knowledge base with Trilium Notes

client/ui/sortable card: fix an issue

Adorian Doran84b834f29f3e
diff --git a/apps/client/src/widgets/react/SortableCard.spec.tsx b/apps/client/src/widgets/react/SortableCard.spec.tsx
index 753c150927..bde1ef62e9 100644
--- a/apps/client/src/widgets/react/SortableCard.spec.tsx
+++ b/apps/client/src/widgets/react/SortableCard.spec.tsx
@@ -353,6 +353,16 @@ describe("SortableCard", () => {
expect(changed.at(-1)?.map((item) => item.key)).toEqual([ "a", "b", "c", "e", "f" ]);
});
+ /** A label says what a button does, and two of them can say the same thing. */
+ it("keeps two buttons that read alike apart", async () => {
+ draw({ itemCreationButtons: [ makes("d", "Delta"), makes("e", "Epsilon") ] });
+
+ expect(adders()).toHaveLength(2);
+
+ await click(adders()[1]);
+ expect(changed.at(-1)?.map((item) => item.key)).toEqual([ "a", "b", "c", "e" ]);
+ });
+
/** Three is as many as the foot of a card can read; a fourth is the caller's mistake. */
it("refuses more than three ways of making an entry", () => {
const buttons = [ makes("d", "D"), makes("e", "E"), makes("f", "F"), makes("g", "G") ];
diff --git a/apps/client/src/widgets/react/SortableCard.tsx b/apps/client/src/widgets/react/SortableCard.tsx
index 30b08e754d..bdd2e0aa67 100644
--- a/apps/client/src/widgets/react/SortableCard.tsx
+++ b/apps/client/src/widgets/react/SortableCard.tsx
@@ -370,9 +370,11 @@ export function SortableCard<T extends SortableItem>({
className="tn-card-section tn-sortable-adders"
onKeyDown={onAddKeyDown}
>
- {itemCreationButtons.map((button) => (
+ {itemCreationButtons.map((button, index) => (
<button
- key={button.label}
+ // The place in the row, which is the only thing that tells two
+ // buttons apart: a label is the caller's to repeat.
+ key={index}
type="button"
className="tn-sortable-adder"
onClick={() => add(button.onCreateItem)}