Skip to content

The open-source app everyone uses to manage agents at work

fix(ui): keep mobile task pickers above the keyboard (#14022)

Dottabd203093235b
diff --git a/tests/storybook-visual/new-issue-dialog-viewport.spec.ts b/tests/storybook-visual/new-issue-dialog-viewport.spec.ts
index b5d154f0b6..f0d21a3f5f 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 9b3b857f89..283a81bc5e 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<HTMLButtonElement, InlineEntitySe
disabled = false,
triggerTestId,
triggerDataSlot,
+ contentStyle,
},
ref,
) {
@@ -148,6 +151,7 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
collisionPadding={16}
className="w-(--sz-calc-6) p-1"
disablePortal={disablePortal}
+ style={contentStyle}
onOpenAutoFocus={(event) => {
event.preventDefault();
inputRef.current?.focus();
@@ -203,7 +207,7 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
}
}}
/>
- <div className="max-h-56 overflow-y-auto overscroll-contain py-1 touch-pan-y">
+ <div data-mobile-entity-picker-list="" className="max-h-56 overflow-y-auto overscroll-contain py-1 touch-pan-y">
{filteredOptions.length === 0 ? (
<p className="px-2 py-2 text-xs text-muted-foreground">{emptyMessage}</p>
) : (
diff --git a/ui/src/components/NewIssueDialog.test.tsx b/ui/src/components/NewIssueDialog.test.tsx
index e2fc6a414e..67ccb108ff 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<HTMLDivElement>("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 884ecf7c45..51dacb2a3b 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<MobileEntityPickerViewportStyle>(() => {
+ 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 04b3313e55..d7d33d5447 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 {