Skip to content

Build your personal knowledge base with Trilium Notes

client/list view: hide the expand/collapse arrow when no children are available

Adorian Doranead519ca38b2
diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.css b/apps/client/src/widgets/collections/legacy/ListOrGridView.css
index fc44a5b511..d32f4de2f2 100644
--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.css
+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.css
@@ -175,6 +175,11 @@
cursor: pointer;
}
+ /* Nothing to reveal: hidden rather than removed, so the title still lines up with its siblings. */
+ .note-expander-empty {
+ visibility: hidden;
+ }
+
.tn-icon {
color: var(--note-list-view-icon-color);
}
diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
index 364b56375c..ac30f1ba8a 100644
--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
@@ -161,6 +161,9 @@ function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expan
// The hover tooltip stands in for the inline preview, so exactly one of the two is offered.
const showsPreview = showPreview?.(note) ?? true;
const showsNotePath = showNotePath?.(note) ?? searchResultsLayout;
+ // Whether expanding would reveal anything at all. Collections always have a preview to show, so
+ // only callers that suppress it can produce a row with nothing underneath.
+ const isExpandable = showsPreview || hasNestedNotes(note, hideSubNotes, resolveChildren);
// Reset expand state if switching to another note, or if user manually toggled expansion state.
useEffect(() => setExpanded(currentLevel <= expandDepth), [ note, currentLevel, expandDepth ]);
@@ -209,8 +212,11 @@ function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expan
data-note-id={note.noteId}
>
<h5>
- <span className={`note-expander ${isExpanded ? "bx bx-chevron-down" : "bx bx-chevron-right"}`}
- onClick={() => setExpanded(!isExpanded)}/>
+ {/* Kept in the DOM when there is nothing to expand, so titles stay aligned. */}
+ <span
+ className={clsx("note-expander", isExpanded ? "bx bx-chevron-down" : "bx bx-chevron-right", { "note-expander-empty": !isExpandable })}
+ onClick={isExpandable ? () => setExpanded(!isExpanded) : undefined}
+ />
<Icon className="note-icon" icon={note.getIcon()} />
<NoteLink className="note-book-title"
notePath={notePath}
@@ -407,6 +413,21 @@ function NoteMenuButton(props: {notePath: string}) {
/>
}
+/**
+ * Whether a row has nested notes to reveal, decided synchronously so the expander can be hidden
+ * before the children are fetched.
+ *
+ * Falls back to the note's own children, which is a slight over-estimate: {@link filterChildNotes}
+ * later drops image links and (when excluded) archived notes, so a note whose only children are of
+ * that kind still offers an expander.
+ */
+function hasNestedNotes(note: FNote, hideSubNotes?: boolean, resolveChildren?: ListViewOptions["resolveChildren"]) {
+ if (hideSubNotes) return false;
+ if (resolveChildren) return resolveChildren(note).length > 0;
+
+ return note.hasChildren();
+}
+
export function getNotePath(parentNote: FNote, childNote: FNote, flat = parentNote.type === "search") {
if (flat) {
// for search note parent, we want to display a non-search path