From 21170d96d3971532303282ccff2ace3f840d7a4e Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 22 Sep 2026 22:30:38 +0200 Subject: [PATCH 1/2] Keep open context menus above the Android keyboard --- TESTING_COVERAGE.md | 2 + .../src/components/Dropdown/index.tsx | 168 ++++++++++-------- .../e2e/tests/resource-context-menu.spec.ts | 32 ++++ 3 files changed, 129 insertions(+), 73 deletions(-) diff --git a/TESTING_COVERAGE.md b/TESTING_COVERAGE.md index 690c535640..f4a8913bbf 100644 --- a/TESTING_COVERAGE.md +++ b/TESTING_COVERAGE.md @@ -62,6 +62,8 @@ keyboard filtering, removal of plugin/website/app creation actions from menus, discovery of their blank starters on a fresh drive, and file/upload searches. Existing app, plugin, and website browser flows create through the catalog, including a website seeded from its selected parent document. +The resource menu check simulates a shrinking visual viewport and requires the +open menu, including its filter, to remain above the keyboard boundary. Mobile AI chat navigation: Chromium covers opening the left sidebar above chat, Back dismissal without leaving the page, the AI settings link, an empty composer diff --git a/browser/data-browser/src/components/Dropdown/index.tsx b/browser/data-browser/src/components/Dropdown/index.tsx index 441c318cbe..6787af47b8 100644 --- a/browser/data-browser/src/components/Dropdown/index.tsx +++ b/browser/data-browser/src/components/Dropdown/index.tsx @@ -209,6 +209,99 @@ export function DropdownMenu({ // if the keyboard is used to navigate the menu items const [useKeys, setUseKeys] = useState(true); + const positionMenu = useCallback(() => { + const menu = dropdownRef.current; + const trigger = triggerRef.current; + + if (!menu || !trigger) return; + + const dialog = menu.closest('dialog'); + const viewport = window.visualViewport; + const visibleTop = viewport?.scale === 1 ? viewport.offsetTop : 0; + const visibleHeight = + viewport?.scale === 1 ? viewport.height : window.innerHeight; + const visibleBottom = visibleTop + visibleHeight; + + // Keyboard animation resizes the visual viewport without necessarily + // changing CSS viewport units. Keep the menu scrollable inside that area. + if (!dialog) { + menu.style.maxHeight = `${Math.max(0, Math.min(window.innerHeight * 0.8, visibleHeight - 16))}px`; + } + + const menuRect = menu.getBoundingClientRect(); + + if (anchorPoint) { + const left = + anchorPoint.x + menuRect.width > window.innerWidth + ? anchorPoint.x - menuRect.width + : anchorPoint.x; + const preferredTop = + anchorPoint.y + menuRect.height > visibleBottom + ? anchorPoint.y - menuRect.height + : anchorPoint.y; + + menu.style.left = `${Math.max(0, left)}px`; + menu.style.top = `${Math.max(visibleTop + 8, Math.min(preferredTop, visibleBottom - menuRect.height - 8))}px`; + + return; + } + + const triggerRect = trigger.getBoundingClientRect(); + + if (dialog) { + const dialogRect = dialog.getBoundingClientRect(); + const relativeTop = triggerRect.y - dialogRect.y; + const relativeLeft = triggerRect.x - dialogRect.x; + const topPos = relativeTop - menuRect.height; + + menu.style.top = `${topPos < 0 ? relativeTop + triggerRect.height : topPos}px`; + + const leftPos = relativeLeft - menuRect.width; + menu.style.left = `${leftPos < 0 ? relativeLeft : relativeLeft - menuRect.width + triggerRect.width}px`; + + return; + } + + // Prefer above the trigger; clamp to the visible viewport if the keyboard + // has covered the trigger or reduced the available space. + const above = triggerRect.y - menuRect.height - MENU_TRIGGER_GAP; + const preferredTop = + above < visibleTop ? triggerRect.bottom + MENU_TRIGGER_GAP : above; + menu.style.top = `${Math.max(visibleTop + 8, Math.min(preferredTop, visibleBottom - menuRect.height - 8))}px`; + + const leftPos = triggerRect.x - menuRect.width; + menu.style.left = `${leftPos < 0 ? triggerRect.x : triggerRect.x - menuRect.width + triggerRect.width}px`; + }, [anchorPoint]); + + useEffect(() => { + if (!isActive) return; + + let frame = 0; + + const schedulePosition = () => { + cancelAnimationFrame(frame); + frame = requestAnimationFrame(positionMenu); + }; + + const viewport = window.visualViewport; + const observer = new ResizeObserver(schedulePosition); + + if (dropdownRef.current) observer.observe(dropdownRef.current); + viewport?.addEventListener('resize', schedulePosition); + viewport?.addEventListener('scroll', schedulePosition); + window.addEventListener('resize', schedulePosition); + window.addEventListener('scroll', schedulePosition, true); + + return () => { + cancelAnimationFrame(frame); + observer.disconnect(); + viewport?.removeEventListener('resize', schedulePosition); + viewport?.removeEventListener('scroll', schedulePosition); + window.removeEventListener('resize', schedulePosition); + window.removeEventListener('scroll', schedulePosition, true); + }; + }, [isActive, positionMenu]); + const handleToggle = useCallback(() => { if (isActive) { handleClose(); @@ -224,7 +317,7 @@ export function DropdownMenu({ return; } - const menuRect = dropdownRef.current.getBoundingClientRect(); + positionMenu(); // The menu is positioned while visibility:hidden, so the entrance // transition must start AFTER it becomes visible — one frame later — @@ -247,80 +340,9 @@ export function DropdownMenu({ }); }; - // A right-click / context menu: position at the cursor point with the - // usual convention (below-right, flipping left/up when it would overflow - // the viewport, clamped to stay on-screen). - if (anchorPoint) { - const left = - anchorPoint.x + menuRect.width > window.innerWidth - ? anchorPoint.x - menuRect.width - : anchorPoint.x; - const top = - anchorPoint.y + menuRect.height > window.innerHeight - ? anchorPoint.y - menuRect.height - : anchorPoint.y; - - dropdownRef.current.style.left = `${Math.max(0, left)}px`; - dropdownRef.current.style.top = `${Math.max(0, top)}px`; - reveal(); - - return; - } - - const triggerRect = triggerRef.current.getBoundingClientRect(); - - // Check if we're inside a dialog - const dialog = dropdownRef.current.closest('dialog'); - - // TODO: Use CSS anchor positioning instead. - if (dialog) { - // For dialogs, use absolute positioning relative to the dialog - const dialogRect = dialog.getBoundingClientRect(); - const relativeTop = triggerRect.y - dialogRect.y; - const relativeLeft = triggerRect.x - dialogRect.x; - - const topPos = relativeTop - menuRect.height; - - // If the top is outside of the dialog, render it below - if (topPos < 0) { - dropdownRef.current.style.top = `${relativeTop + triggerRect.height}px`; - } else { - dropdownRef.current.style.top = `${topPos}px`; - } - - const leftPos = relativeLeft - menuRect.width; - - // If the left is outside of the dialog, render it to the right - if (leftPos < 0) { - dropdownRef.current.style.left = `${relativeLeft}px`; - } else { - dropdownRef.current.style.left = `${relativeLeft - menuRect.width + triggerRect.width}px`; - } - } else { - // Prefer opening above the trigger, below when there's no room. A - // small gap instead of overlapping the trigger — covering it half-way - // made it unclickable for toggling the menu closed. - const topPos = triggerRect.y - menuRect.height - MENU_TRIGGER_GAP; - - if (topPos < 0) { - dropdownRef.current.style.top = `${triggerRect.bottom + MENU_TRIGGER_GAP}px`; - } else { - dropdownRef.current.style.top = `${topPos}px`; - } - - const leftPos = triggerRect.x - menuRect.width; - - // If the left is outside of the screen, render it to the right - if (leftPos < 0) { - dropdownRef.current.style.left = `${triggerRect.x}px`; - } else { - dropdownRef.current.style.left = `${triggerRect.x - menuRect.width + triggerRect.width}px`; - } - } - reveal(); }); - }, [isActive, setIsActive, anchorPoint, searchable]); + }, [isActive, handleClose, setIsActive, positionMenu, searchable]); const handleMouseOverMenu = useCallback(() => { setUseKeys(false); diff --git a/browser/e2e/tests/resource-context-menu.spec.ts b/browser/e2e/tests/resource-context-menu.spec.ts index bd9752bd0a..182c545dbb 100644 --- a/browser/e2e/tests/resource-context-menu.spec.ts +++ b/browser/e2e/tests/resource-context-menu.spec.ts @@ -56,6 +56,38 @@ async function openContextMenu(page: Page, target: Locator, items: Locator[]) { test.describe('resource context menu', () => { test.beforeEach(before); + test('open menu follows the visible viewport as a keyboard appears', async ({ + page, + }) => { + await page.setViewportSize({ width: 390, height: 844 }); + await page.getByRole('button', { name: 'More', exact: true }).click(); + const menu = page.getByRole('menu'); + await expect(menu).toBeVisible(); + const originalTop = (await menu.boundingBox())!.y; + + for (const height of [620, 480]) { + await page.evaluate(visibleHeight => { + const viewport = window.visualViewport!; + Object.defineProperty(viewport, 'height', { + configurable: true, + value: visibleHeight, + }); + viewport.dispatchEvent(new Event('resize')); + }, height); + + await expect + .poll(async () => { + const bounds = (await menu.boundingBox())!; + + return bounds.y + bounds.height; + }) + .toBeLessThanOrEqual(height - 8); + } + + expect((await menu.boundingBox())!.y).toBeLessThan(originalTop); + await expect(page.getByRole('textbox', { name: 'Filter actions' })).toBeFocused(); + }); + test('sidebar link + table cell open the resource menu on right-click', async ({ page, }: { From 1fce8dcab48e213989de76d19797fad78c75a389 Mon Sep 17 00:00:00 2001 From: Joep Meindertsma Date: Tue, 22 Sep 2026 23:29:21 +0200 Subject: [PATCH 2/2] Fix workspace lint for context menu PR --- .../e2e/tests/resource-context-menu.spec.ts | 4 +++- .../e2e/tests/right-panel-lifecycle.spec.ts | 20 ++++++++++++++----- browser/lib/src/client-db.ts | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/browser/e2e/tests/resource-context-menu.spec.ts b/browser/e2e/tests/resource-context-menu.spec.ts index 182c545dbb..b4e49c7b5a 100644 --- a/browser/e2e/tests/resource-context-menu.spec.ts +++ b/browser/e2e/tests/resource-context-menu.spec.ts @@ -85,7 +85,9 @@ test.describe('resource context menu', () => { } expect((await menu.boundingBox())!.y).toBeLessThan(originalTop); - await expect(page.getByRole('textbox', { name: 'Filter actions' })).toBeFocused(); + await expect( + page.getByRole('textbox', { name: 'Filter actions' }), + ).toBeFocused(); }); test('sidebar link + table cell open the resource menu on right-click', async ({ diff --git a/browser/e2e/tests/right-panel-lifecycle.spec.ts b/browser/e2e/tests/right-panel-lifecycle.spec.ts index f1b589235f..c3a648f1fc 100644 --- a/browser/e2e/tests/right-panel-lifecycle.spec.ts +++ b/browser/e2e/tests/right-panel-lifecycle.spec.ts @@ -6,11 +6,15 @@ async function expectLeftSidebarClosed(page: Page) { await expect .poll(async () => - sidebar.evaluate(element => element.parentElement!.getBoundingClientRect().width), + sidebar.evaluate( + element => element.parentElement!.getBoundingClientRect().width, + ), ) .toBe(0); await expect - .poll(() => sidebar.evaluate(element => Number(getComputedStyle(element).opacity))) + .poll(() => + sidebar.evaluate(element => Number(getComputedStyle(element).opacity)), + ) .toBe(0); } @@ -26,7 +30,9 @@ for (const [name, trigger, panel] of [ const sidebar = page.getByTestId('sidebar'); await expect .poll(() => - sidebar.evaluate(element => element.parentElement!.getBoundingClientRect().width), + sidebar.evaluate( + element => element.parentElement!.getBoundingClientRect().width, + ), ) .toBeGreaterThan(0); await page.mouse.move(700, 400); @@ -35,7 +41,9 @@ for (const [name, trigger, panel] of [ await expectLeftSidebarClosed(page); await page.mouse.move(2, 400); await expect - .poll(() => sidebar.evaluate(element => Number(getComputedStyle(element).opacity))) + .poll(() => + sidebar.evaluate(element => Number(getComputedStyle(element).opacity)), + ) .toBe(0); }); } @@ -49,7 +57,9 @@ test('opening meeting chat closes the left sidebar at tablet width', async ({ .poll(() => page .getByTestId('sidebar') - .evaluate(element => element.parentElement!.getBoundingClientRect().width), + .evaluate( + element => element.parentElement!.getBoundingClientRect().width, + ), ) .toBeGreaterThan(0); await page.getByRole('button', { name: 'New Meeting' }).first().click(); diff --git a/browser/lib/src/client-db.ts b/browser/lib/src/client-db.ts index cbc33d1ce1..d7e09572df 100644 --- a/browser/lib/src/client-db.ts +++ b/browser/lib/src/client-db.ts @@ -1154,8 +1154,8 @@ export class ClientDbWorker { }); } - // eslint-disable-next-line @typescript-eslint/no-explicit-any private sendToLeader( + // eslint-disable-next-line @typescript-eslint/no-explicit-any msg: Record, retries = 1, ): Promise {