AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(web): keep memo context menus within the viewport
tianma-if12b100f6805e
diff --git a/apps/web/src/components/MemoListPane.tsx b/apps/web/src/components/MemoListPane.tsxindex 974248dc..8cec5578 100644--- a/apps/web/src/components/MemoListPane.tsx+++ b/apps/web/src/components/MemoListPane.tsx@@ -901,15 +901,7 @@ export const MemoListPane = ({};const openMemoContextMenuAt = (memo: MemoSummary, clientX: number, clientY: number) => {- const menuWidth = 224;- // Keep enough room for the full action list. Radix can still adjust the- // final position, but this prevents the initial placement from starting- // below the viewport on short or zoomed desktop viewports.- const menuHeight = view === "trash" ? 216 : 392;- const x = Math.min(clientX, Math.max(12, window.innerWidth - menuWidth - 12));- const y = Math.min(clientY, Math.max(12, window.innerHeight - menuHeight - 12));-- setMemoContextMenu({ memo, x, y });+ setMemoContextMenu({ memo, x: clientX, y: clientY });};const handleOpenMemoContextMenu = (memo: MemoSummary, event: MouseEvent<HTMLElement>) => {@@ -1525,12 +1517,18 @@ export const MemoListPane = ({<div style={{ position: "fixed", left: memoContextMenu.x, top: memoContextMenu.y, zIndex: 100 }}><DropdownMenu modal={false} open={true} onOpenChange={(open) => { if (!open) setMemoContextMenu(null); }}><DropdownMenuTrigger asChild>- <span className="sr-only" />+ <span className="block h-0 w-0" /></DropdownMenuTrigger><DropdownMenuContent+ // A side anchor lets Radix shift the full menu vertically using+ // its measured height, even when neither side of the click fits.+ side="right"+ sideOffset={0}align="start"+ sticky="always"+ collisionPadding={12}onCloseAutoFocus={(event) => event.preventDefault()}- className="max-h-[calc(100dvh-1.5rem)] w-56 max-w-[calc(100vw-1.5rem)] overflow-y-auto bg-card border border-slate-200 rounded-md py-1 shadow-md duration-0 data-[state=open]:animate-none data-[state=closed]:animate-none"+ className="max-h-[min(calc(100dvh-1.5rem),var(--radix-dropdown-menu-content-available-height))] w-56 max-w-[calc(100vw-1.5rem)] overflow-y-auto bg-card border border-slate-200 rounded-md py-1 shadow-md duration-0 data-[state=open]:animate-none data-[state=closed]:animate-none"data-memo-actions-menu><DropdownMenuItem@@ -1613,7 +1611,7 @@ export const MemoListPane = ({<Folder className="h-4 w-4" /><span className="min-w-0 flex-1 truncate">{t("memoList.moveToNotebook")}</span></DropdownMenuSubTrigger>- <DropdownMenuSubContent className="max-h-64 w-56 overflow-y-auto">+ <DropdownMenuSubContent collisionPadding={12} sticky="always" className="max-h-[min(16rem,var(--radix-dropdown-menu-content-available-height))] w-56 overflow-y-auto">{moveNotebookOptions.map((option) => (<DropdownMenuItemkey={option.id}diff --git a/tests/e2e/memo-list-actions.spec.ts b/tests/e2e/memo-list-actions.spec.tsindex 1c2c0d05..1f0c7f93 100644--- a/tests/e2e/memo-list-actions.spec.ts+++ b/tests/e2e/memo-list-actions.spec.ts@@ -1,5 +1,36 @@import { expect, test } from "@playwright/test";+for (const height of [900, 720, 420]) {+ test(`keeps all memo actions reachable in a ${height}px viewport`, async ({ page }) => {+ await page.setViewportSize({ width: 1280, height });+ await page.goto("/");+ const card = page.locator('[data-memo-id="memo_demo_overview"]');+ await card.locator("button").first().click({ button: "right" });++ const menu = page.locator("[data-memo-actions-menu]");+ await expect(menu).toBeVisible();+ await expect.poll(async () => {+ const box = await menu.boundingBox();+ return Boolean(box && box.y >= 12 && box.y + box.height <= height - 12 && box.x >= 12 && box.x + box.width <= 1280 - 12);+ }).toBe(true);++ const sizes = await menu.evaluate(node => ({ client: node.clientHeight, scroll: node.scrollHeight }));+ if (height === 420) expect(sizes.scroll).toBeGreaterThan(sizes.client);+ else expect(sizes.scroll).toBeLessThanOrEqual(sizes.client + 1);++ // End must reveal the last action without invoking a destructive action.+ await page.keyboard.press("End");+ await expect(menu.getByRole("menuitem").last()).toBeFocused();+ await expect.poll(() => menu.getByRole("menuitem").last().evaluate(node => {+ const item = node.getBoundingClientRect();+ const parent = node.closest("[data-memo-actions-menu]")!.getBoundingClientRect();+ return item.top >= parent.top && item.bottom <= parent.bottom;+ })).toBe(true);+ await page.keyboard.press("Escape");+ await expect(menu).toBeHidden();+ });+}+test("anchors a memo's more-actions menu to its visible trigger", async ({ page }) => {await page.goto("/");