Skip to content

Build your personal knowledge base with Trilium Notes

client/breadcrumb: tweak the dropdowns

Adorian Doran3767d2ca80f6
diff --git a/apps/client/src/widgets/layout/Breadcrumb.spec.tsx b/apps/client/src/widgets/layout/Breadcrumb.spec.tsx
index d791e68df5..e535d0ca18 100644
--- a/apps/client/src/widgets/layout/Breadcrumb.spec.tsx
+++ b/apps/client/src/widgets/layout/Breadcrumb.spec.tsx
@@ -6,7 +6,9 @@ import type { MenuCommandItem } from "../../menus/context_menu";
import protectedSessionHolder from "../../services/protected_session_holder";
import { buildNote } from "../../test/easy-froca";
import { renderInto } from "../../test/render";
-import { BreadcrumbNoteTitle, buildChildNoteItems, noteTitleHtml } from "./Breadcrumb";
+import {
+ BreadcrumbNoteTitle, BreadcrumbSeparator, buildChildNoteItems, noteTitleHtml
+} from "./Breadcrumb";
vi.mock("../../services/i18n", async (importOriginal) => ({
...(await importOriginal<typeof import("../../services/i18n")>()),
@@ -50,6 +52,34 @@ describe("BreadcrumbNoteTitle", () => {
});
});
+describe("BreadcrumbSeparator", () => {
+ /** Whether the menu of the separator after `noteId` offers a filter input. */
+ function hasFilterInput(noteId: string) {
+ let container: HTMLElement | undefined;
+ act(() => {
+ container = renderInto(
+ <BreadcrumbSeparator
+ notePath={`root/${noteId}`} noteContext={undefined} hideArchivedNotes={false}
+ />
+ );
+ });
+ const toggle = container?.querySelector("button");
+ expect(toggle).toBeTruthy();
+ act(() => toggle?.click());
+ expect(document.querySelector(".breadcrumb-child-list")).toBeTruthy();
+ const hasInput = !!document.querySelector(".breadcrumb-child-list .tn-menu-filter-input");
+ act(() => toggle?.click());
+ return hasInput;
+ }
+
+ it("offers a filter input only for a note with children", () => {
+ buildNote({ id: "parent", title: "Parent", children: [ { title: "Child" } ] });
+ buildNote({ id: "leaf", title: "Leaf" });
+ expect(hasFilterInput("parent")).toBe(true);
+ expect(hasFilterInput("leaf")).toBe(false);
+ });
+});
+
describe("noteTitleHtml", () => {
afterEach(() => {
vi.restoreAllMocks();
diff --git a/apps/client/src/widgets/layout/Breadcrumb.tsx b/apps/client/src/widgets/layout/Breadcrumb.tsx
index 4aed864f7c..4b17fc515d 100644
--- a/apps/client/src/widgets/layout/Breadcrumb.tsx
+++ b/apps/client/src/widgets/layout/Breadcrumb.tsx
@@ -189,7 +189,7 @@ interface BreadcrumbSeparatorProps {
hideArchivedNotes: boolean;
}
-function BreadcrumbSeparator(props: BreadcrumbSeparatorProps) {
+export function BreadcrumbSeparator(props: BreadcrumbSeparatorProps) {
const notePathComponents = (props.notePath ?? "").split("/");
const parentNoteId = notePathComponents.at(-1);
const parentNote = useNote(parentNoteId);
@@ -207,7 +207,7 @@ function BreadcrumbSeparator(props: BreadcrumbSeparatorProps) {
hideToggleArrow
dropdownContainerClassName="breadcrumb-child-list"
placement="top"
- filterable
+ filterable={!!parentNote?.hasChildren()}
keepOrder
>
<BreadcrumbSeparatorDropdownContent {...props} />