From bd203093235b28631760a76b602b35028322e06f Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Fri, 25 Sep 2026 08:37:26 -0700 Subject: [PATCH] fix(ui): keep mobile task pickers above the keyboard (#14022) ## Thinking Path > - Paperclip helps people manage AI agents and their tasks. > - The New Task dialog lets a person select an assignee and a project. > - A mobile browser reduces the visible viewport when the software keyboard opens. > - The dialog accepted invalid viewport data, and the pickers stayed inside a transformed container. > - This behavior could collapse the dialog or move a picker search field above the visible area. > - This pull request validates viewport data and puts mobile pickers in the visible viewport. > - The benefit is that a mobile user can see and use each picker while the keyboard is open. ## Linked Issues or Issue Description **What happened?** On a mobile device, the Assignee and Project pickers in the New Task dialog could move above the visible viewport. A short invalid viewport value could also collapse the dialog to a line. **Expected behavior** The dialog and each open picker must stay in the visible viewport while the software keyboard is open. **Steps to reproduce** 1. Open the New Task dialog in a mobile browser. 2. Open the Assignee picker or the Project picker. 3. Focus the picker search field so that the software keyboard opens. 4. Observe that the picker can move above the visible viewport. **Paperclip version or commit** `efce9356b5` **Deployment mode** Local dev and hosted browser UI. ## What Changed - Ignore zero, negative, and non-finite Visual Viewport measurements. - Keep the last safe dialog geometry until the browser gives a valid measurement. - Put entity pickers outside the transformed dialog container. - Size and position the mobile picker from the dialog Visual Viewport values. - Add unit tests for invalid viewport recovery. - Add Chromium tests for the Assignee and Project picker states. ## Verification - `pnpm exec vitest run ui/src/components/NewIssueDialog.test.tsx` passed with 34 tests. - The Chromium viewport test passed 35 of 35 runs with five repeats and no retries. - `pnpm --filter @paperclipai/ui typecheck` passed. - `pnpm check:token-gates` passed. - `pnpm build-storybook` passed. - `pnpm -r typecheck` passed. - `pnpm build` passed. - A full local Vitest run reached restricted workspace-runtime tests that require sibling worktree and runtime writes. Remote CI will run the supported test environment. ## Risks - Risk is low because the new picker layout applies only to mobile widths. - The layout depends on Visual Viewport data when the browser supplies valid values. - Unit and browser tests cover invalid data, mobile pickers, tablet layout, and desktop layout. > This change fixes a focused UI bug. It does not duplicate a core feature in `ROADMAP.md`. ## Model Used - OpenAI Codex with GPT-5. The agent used reasoning, repository tools, code execution, and browser automation. The runtime did not expose the context window size. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip --- .../new-issue-dialog-viewport.spec.ts | 93 ++++++++++++++++++- ui/src/components/InlineEntitySelector.tsx | 8 +- ui/src/components/NewIssueDialog.test.tsx | 51 ++++++++++ ui/src/components/NewIssueDialog.tsx | 38 ++++++-- ui/src/index.css | 20 +++- 5 files changed, 196 insertions(+), 14 deletions(-) diff --git a/tests/storybook-visual/new-issue-dialog-viewport.spec.ts b/tests/storybook-visual/new-issue-dialog-viewport.spec.ts index b5d154f0b69..f0d21a3f5fc 100644 --- a/tests/storybook-visual/new-issue-dialog-viewport.spec.ts +++ b/tests/storybook-visual/new-issue-dialog-viewport.spec.ts @@ -35,9 +35,9 @@ async function installVisualViewport(page: Page, layoutHeight: number) { }, { initialHeight: layoutHeight }); } -async function renderDialog(page: Page, viewport: ViewportCase) { +async function renderDialog(page: Page, viewport: ViewportCase, initialVisualHeight = viewport.layoutHeight) { await page.setViewportSize({ width: viewport.width, height: viewport.layoutHeight }); - await installVisualViewport(page, viewport.layoutHeight); + await installVisualViewport(page, initialVisualHeight); await page.goto(`/iframe.html?id=${STORY_ID}&viewMode=story`, { waitUntil: "load" }); await page.waitForFunction(() => { const body = document.body; @@ -54,6 +54,95 @@ async function renderDialog(page: Page, viewport: ViewportCase) { return dialog; } +test("does not collapse the new-task dialog during a transient zero-height visual viewport reading", async ({ page }) => { + const viewport = VIEWPORT_CASES[0]; + const dialog = await renderDialog(page, viewport, 0); + + await expect.poll(async () => dialog.evaluate((element) => { + const rect = element.getBoundingClientRect(); + return { top: rect.top, bottom: rect.bottom }; + })).toEqual({ top: 16, bottom: viewport.layoutHeight - 16 }); + + await constrainVisualViewport(page, viewport); + await expect.poll(async () => dialog.evaluate((element) => { + const rect = element.getBoundingClientRect(); + return { top: rect.top, bottom: rect.bottom }; + })).toEqual({ + top: viewport.offsetTop + 16, + bottom: viewport.offsetTop + viewport.visualHeight - 16, + }); + + await page.evaluate(() => { + const visualViewport = window.visualViewport as VisualViewport & { + height: number; + offsetTop: number; + }; + visualViewport.height = 0; + visualViewport.offsetTop = Number.NaN; + visualViewport.dispatchEvent(new Event("resize")); + }); + await expect.poll(async () => dialog.evaluate((element) => { + const rect = element.getBoundingClientRect(); + return { top: rect.top, bottom: rect.bottom }; + })).toEqual({ + top: viewport.offsetTop + 16, + bottom: viewport.offsetTop + viewport.visualHeight - 16, + }); +}); + +for (const { pickerName, triggerName, query, selectionName } of [ + { + pickerName: "assignee", + triggerName: "CodexCoder", + query: "QA", + selectionName: "QAChecker", + }, + { + pickerName: "project", + triggerName: "Board UI", + query: "Runtime", + selectionName: "Agent Runtime", + }, +]) { + test(`keeps the open ${pickerName} picker inside the mobile visual viewport`, async ({ page }) => { + const viewport = VIEWPORT_CASES[0]; + const dialog = await renderDialog(page, viewport); + await constrainVisualViewport(page, viewport); + + const trigger = dialog.getByRole("button", { name: triggerName }); + await trigger.click(); + const picker = page.locator("[data-mobile-entity-picker]"); + await expect(picker).toBeVisible(); + await expect(picker.locator("input")).toBeFocused(); + + const geometry = await picker.evaluate((element) => { + const pickerRect = element.getBoundingClientRect(); + const inputRect = element.querySelector("input")!.getBoundingClientRect(); + const dialogElement = document.querySelector('[data-slot="dialog-content"]'); + return { + pickerTop: pickerRect.top, + pickerBottom: pickerRect.bottom, + inputTop: inputRect.top, + inputBottom: inputRect.bottom, + portalledOutsideDialog: !dialogElement?.contains(element), + }; + }); + const visibleTop = viewport.offsetTop; + const visibleBottom = viewport.offsetTop + viewport.visualHeight; + expect(geometry.pickerTop).toBeGreaterThanOrEqual(visibleTop); + expect(geometry.pickerBottom).toBeLessThanOrEqual(visibleBottom); + expect(geometry.inputTop).toBeGreaterThanOrEqual(visibleTop); + expect(geometry.inputBottom).toBeLessThanOrEqual(visibleBottom); + expect(geometry.portalledOutsideDialog).toBe(true); + + const searchInput = picker.locator("input"); + await searchInput.fill(query); + await picker.getByRole("button", { name: selectionName }).click(); + await expect(picker).toBeHidden(); + await expect(dialog.getByRole("button", { name: selectionName })).toBeVisible(); + }); +} + async function constrainVisualViewport(page: Page, viewport: ViewportCase) { await page.evaluate(({ height, offsetTop }) => { const visualViewport = window.visualViewport as VisualViewport & { diff --git a/ui/src/components/InlineEntitySelector.tsx b/ui/src/components/InlineEntitySelector.tsx index 9b3b857f893..283a81bc5ef 100644 --- a/ui/src/components/InlineEntitySelector.tsx +++ b/ui/src/components/InlineEntitySelector.tsx @@ -1,4 +1,4 @@ -import { forwardRef, useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react"; +import { forwardRef, useCallback, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react"; import { Check } from "lucide-react"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover"; import { orderItemsBySelectedAndRecent } from "../lib/recent-selections"; @@ -33,6 +33,8 @@ interface InlineEntitySelectorProps { triggerTestId?: string; /** Optional slot name used by consuming surfaces for scoped presentation rules. */ triggerDataSlot?: string; + /** Runtime geometry variables for the portalled mobile picker sheet. */ + contentStyle?: CSSProperties; } const EMPTY_RECENT_OPTION_IDS: string[] = []; @@ -57,6 +59,7 @@ export const InlineEntitySelector = forwardRef { event.preventDefault(); inputRef.current?.focus(); @@ -203,7 +207,7 @@ export const InlineEntitySelector = forwardRef -
+
{filteredOptions.length === 0 ? (

{emptyMessage}

) : ( diff --git a/ui/src/components/NewIssueDialog.test.tsx b/ui/src/components/NewIssueDialog.test.tsx index e2fc6a414e2..67ccb108ffa 100644 --- a/ui/src/components/NewIssueDialog.test.tsx +++ b/ui/src/components/NewIssueDialog.test.tsx @@ -1328,6 +1328,57 @@ describe("NewIssueDialog", () => { act(() => root.unmount()); }); + it("ignores transient invalid visual viewport measurements and keeps the last valid layout", async () => { + const visualViewport = new EventTarget() as EventTarget & { + height: number; + offsetTop: number; + }; + visualViewport.height = 0; + visualViewport.offsetTop = 0; + Object.defineProperty(window, "visualViewport", { + configurable: true, + value: visualViewport, + }); + Object.defineProperty(window, "innerHeight", { + configurable: true, + value: 844, + }); + + const { root } = renderDialog(container); + await flush(); + + const dialogContent = Array.from(container.querySelectorAll("div")).find((element) => + element.className.includes("max-h-(--new-issue-dialog-height)"), + ); + expect(dialogContent?.style.getPropertyValue("--new-issue-visual-viewport-height")).toBe(""); + expect(dialogContent?.style.top).toBe(""); + expect(dialogContent?.style.height).toBe(""); + expect(dialogContent?.style.translate).toBe(""); + + visualViewport.height = 420; + visualViewport.offsetTop = 24; + await act(async () => { + visualViewport.dispatchEvent(new Event("resize")); + }); + + expect(dialogContent?.style.getPropertyValue("--new-issue-visual-viewport-height")).toBe("420px"); + expect(dialogContent?.style.top).toBe("var(--new-issue-dialog-top)"); + expect(dialogContent?.style.height).toBe("var(--new-issue-dialog-height)"); + + visualViewport.height = 0; + visualViewport.offsetTop = Number.NaN; + await act(async () => { + visualViewport.dispatchEvent(new Event("resize")); + }); + + expect(dialogContent?.style.getPropertyValue("--new-issue-visual-viewport-height")).toBe("420px"); + expect(dialogContent?.style.getPropertyValue("--new-issue-visual-viewport-offset-top")).toBe("24px"); + expect(dialogContent?.style.top).toBe("var(--new-issue-dialog-top)"); + expect(dialogContent?.style.height).toBe("var(--new-issue-dialog-height)"); + + act(() => root.unmount()); + }); + it("hides the priority chip and mobile priority option (PAP-411)", async () => { const { root } = renderDialog(container); await flush(); diff --git a/ui/src/components/NewIssueDialog.tsx b/ui/src/components/NewIssueDialog.tsx index 884ecf7c450..51dacb2a3b5 100644 --- a/ui/src/components/NewIssueDialog.tsx +++ b/ui/src/components/NewIssueDialog.tsx @@ -101,9 +101,24 @@ type NewIssueDialogViewportStyle = CSSProperties & { "--new-issue-dialog-height"?: string; }; +type MobileEntityPickerViewportStyle = CSSProperties & { + "--mobile-entity-picker-visual-viewport-height"?: string; + "--mobile-entity-picker-visual-viewport-bottom"?: string; +}; + function readVisualViewportLayout(): VisualViewportLayout | null { if (typeof window === "undefined" || !window.visualViewport) return null; const { height, offsetTop } = window.visualViewport; + // Mobile browsers can briefly report unusable geometry while the visual + // viewport initializes or animates. Applying it collapses the dialog. + if ( + !Number.isFinite(height) + || height <= 0 + || !Number.isFinite(offsetTop) + || offsetTop < 0 + ) { + return null; + } return { height, offsetTop, @@ -125,7 +140,11 @@ function useVisualViewportLayout(enabled: boolean) { const viewport = window.visualViewport; if (!viewport) return; - const updateLayout = () => setLayout(readVisualViewportLayout()); + const updateLayout = () => { + const nextLayout = readVisualViewportLayout(); + // Keep the last valid keyboard geometry during transient invalid readings. + if (nextLayout) setLayout(nextLayout); + }; updateLayout(); viewport.addEventListener("resize", updateLayout); viewport.addEventListener("scroll", updateLayout); @@ -1327,6 +1346,13 @@ export function NewIssueDialog() { : {}), }; }, [visualViewportLayout]); + const entityPickerViewportStyle = useMemo(() => { + if (!visualViewportLayout) return {}; + return { + "--mobile-entity-picker-visual-viewport-height": `${visualViewportLayout.height}px`, + "--mobile-entity-picker-visual-viewport-bottom": `${visualViewportLayout.offsetTop + visualViewportLayout.height}px`, + }; + }, [visualViewportLayout]); useEffect(() => { if (!visualViewportLayout?.constrained) return; @@ -1491,7 +1517,7 @@ export function NewIssueDialog() { placeholder="Assignee" className="h-8 px-2.5 py-0 sm:h-auto sm:px-2 sm:py-1" triggerDataSlot="new-issue-compact-control" - disablePortal + contentStyle={entityPickerViewportStyle} noneLabel="No assignee" searchPlaceholder="Search assignees..." emptyMessage="No assignees found." @@ -1552,7 +1578,7 @@ export function NewIssueDialog() { placeholder="Project" className="h-8 px-2.5 py-0 sm:h-auto sm:px-2 sm:py-1" triggerDataSlot="new-issue-compact-control" - disablePortal + contentStyle={entityPickerViewportStyle} noneLabel="No project" searchPlaceholder="Search projects..." emptyMessage="No projects found." @@ -1663,7 +1689,7 @@ export function NewIssueDialog() { options={assigneeOptions} recentOptionIds={recentAssigneeOptionIds} placeholder="Reviewer" - disablePortal + contentStyle={entityPickerViewportStyle} noneLabel="No reviewer" searchPlaceholder="Search reviewers..." emptyMessage="No reviewers found." @@ -1708,7 +1734,7 @@ export function NewIssueDialog() { options={assigneeOptions} recentOptionIds={recentAssigneeOptionIds} placeholder="Approver" - disablePortal + contentStyle={entityPickerViewportStyle} noneLabel="No approver" searchPlaceholder="Search approvers..." emptyMessage="No approvers found." @@ -1952,7 +1978,7 @@ export function NewIssueDialog() { value={assigneeModelOverride} options={modelOverrideOptions} placeholder="Default model" - disablePortal + contentStyle={entityPickerViewportStyle} noneLabel="Default model" searchPlaceholder="Search models..." emptyMessage="No models found." diff --git a/ui/src/index.css b/ui/src/index.css index 04b3313e559..d7d33d54471 100644 --- a/ui/src/index.css +++ b/ui/src/index.css @@ -230,6 +230,8 @@ --new-issue-visual-viewport-offset-top: 0px; --new-issue-dialog-top-gap: max(1rem, env(safe-area-inset-top)); --new-issue-dialog-bottom-gap: max(1rem, env(safe-area-inset-bottom)); + --mobile-entity-picker-visual-viewport-height: 100dvh; + --mobile-entity-picker-visual-viewport-bottom: 100dvh; /* ──────────────────────────────────────────────────────────────────────── Motion tokens — chat-style task thread (default; classic legacy view sits @@ -3005,19 +3007,29 @@ span.paperclip-mention-chip[data-mention-kind="external-object"] { software keyboard. The fixed sheet also avoids scale motion during mobile viewport resizing. */ @media (max-width: 40rem) { + [data-radix-popper-content-wrapper]:has(> [data-mobile-entity-picker]) { + transform: none !important; + } + [data-mobile-entity-picker] { position: fixed !important; - inset: auto calc(var(--spacing) * 4) max(calc(var(--spacing) * 4), env(safe-area-inset-bottom)) !important; + inset: calc(var(--mobile-entity-picker-visual-viewport-bottom) - var(--spacing) * 4) + calc(var(--spacing) * 4) auto !important; width: auto !important; max-width: none !important; - max-height: calc(100dvh - calc(var(--spacing) * 8)) !important; + max-height: calc(var(--mobile-entity-picker-visual-viewport-height) - var(--spacing) * 8) !important; transform: none !important; + translate: 0 -100% !important; transform-origin: bottom center !important; animation: none !important; } - [data-mobile-entity-picker] [data-slot="command-list"] { - max-height: min(var(--sz-300px), calc(100dvh - calc(var(--spacing) * 24))) !important; + [data-mobile-entity-picker] [data-slot="command-list"], + [data-mobile-entity-picker-list] { + max-height: min( + var(--sz-300px), + calc(var(--mobile-entity-picker-visual-viewport-height) - var(--spacing) * 24) + ) !important; } } :root {