Skip to content

Build your personal knowledge base with Trilium Notes

client/ui/dropwdown: fix some issues

Adorian Doranc3d5f78add5a
diff --git a/apps/client/src/widgets/react/Dropdown.spec.tsx b/apps/client/src/widgets/react/Dropdown.spec.tsx
index 320e9a36e0..c00c7a761b 100644
--- a/apps/client/src/widgets/react/Dropdown.spec.tsx
+++ b/apps/client/src/widgets/react/Dropdown.spec.tsx
@@ -561,11 +561,13 @@ describe("Dropdown", () => {
// Nothing placed it beside the toggle; the `.mobile-bottom-menu` rules do.
expect([ popup()?.style.left, popup()?.style.top ]).toEqual([ "", "" ]);
expect([ ...cover.classList ]).toEqual([ "show", "global-menu-cover" ]);
+ expect(document.body.classList.contains("backdrop-open")).toBe(true);
// A tap on the cover is one outside the menu.
cover.dispatchEvent(new PointerEvent("pointerdown", { bubbles: true }));
await vi.waitFor(() => expect(popup()).toBeNull());
expect(cover.classList.contains("show")).toBe(false);
+ expect(document.body.classList.contains("backdrop-open")).toBe(false);
cover.remove();
});
@@ -593,6 +595,7 @@ describe("Dropdown", () => {
expect(popup()?.classList.contains("mobile-bottom-menu")).toBe(false);
const { left, top, maxHeight } = popup()?.style ?? {};
expect([ left, top, maxHeight ]).toEqual([ "", "", "" ]);
+ expect(document.body.classList.contains("backdrop-open")).toBe(true);
click(toggle);
await vi.waitFor(() => expect(popup()).toBeNull());
@@ -634,6 +637,7 @@ describe("Dropdown", () => {
expect(popup()?.classList.contains("mobile-bottom-menu")).toBe(false);
expect(popup()?.style.top).toBe("82px");
expect(cover.classList.contains("show")).toBe(false);
+ expect(document.body.classList.contains("backdrop-open")).toBe(false);
cover.remove();
});
diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsx
index 11e0680ef1..43d98e5d53 100644
--- a/apps/client/src/widgets/react/Dropdown.tsx
+++ b/apps/client/src/widgets/react/Dropdown.tsx
@@ -202,7 +202,7 @@ function DropdownToggle({ id, className, buttonClassName, title, text, dropdownC
const triggerRef = useRef<HTMLButtonElement | null>(null);
const popupRef = useRef<HTMLDivElement | null>(null);
const [ shown, setShown ] = useState(false);
- useBodyClass("backdrop-open", shown && !!backdrop);
+ useBodyClass("backdrop-open", shown && (!!backdrop || mobileBackdrop));
/** The item to start at once the popup shows, for a popup a key on the toggle opened. */
const [ startAt, setStartAt ] = useState<"first" | "last">();