Skip to content

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

fix(ui): allow touch scrolling in new-task pickers (#14599)

Dotta81a52eb740fb
diff --git a/doc/DEVELOPING.md b/doc/DEVELOPING.md
index cbc348d957..8a97fa731b 100644
--- a/doc/DEVELOPING.md
+++ b/doc/DEVELOPING.md
@@ -122,6 +122,13 @@ Grok uses its adapter's reasoning levels, including for its default model.
Kimi shows effort only when its agent uses the CLI engine, including with its
default model, because the default ACP engine ignores effort.
+Mobile entity picker sheets use a modal popover so touch scrolling stays inside
+the sheet even when it is portalled outside the new-task dialog. Run
+`pnpm exec playwright test --config tests/e2e/playwright.config.ts tests/e2e/new-task-picker-touch.spec.ts`
+to verify native touch scrolling and selection in both assignee and model lists.
+The test uses a fixed model catalog and a reduced viewport to cover limited
+space while the phone keyboard is open; it does not require a provider login.
+
The Storybook visual regression suite uses external PNG baselines instead of
committed screenshots:
diff --git a/tests/e2e/new-task-picker-touch.spec.ts b/tests/e2e/new-task-picker-touch.spec.ts
new file mode 100644
index 0000000000..a78f25e373
--- /dev/null
+++ b/tests/e2e/new-task-picker-touch.spec.ts
@@ -0,0 +1,122 @@
+import { randomUUID } from "node:crypto";
+import { expect, test, type APIResponse, type Locator, type Page } from "@playwright/test";
+
+async function json(response: APIResponse) {
+ expect(response.ok(), await response.text()).toBe(true);
+ return response.json();
+}
+
+async function swipeToLastOption(page: Page, picker: Locator) {
+ const list = picker.locator("[data-mobile-entity-picker-list]");
+ const last = list.getByRole("button").last();
+ // visualViewport resize updates React state after the browser viewport changes.
+ await expect.poll(async () => {
+ const bounds = (await picker.boundingBox())!;
+ return bounds.y + bounds.height;
+ }).toBeLessThanOrEqual(page.viewportSize()!.height);
+ const session = await page.context().newCDPSession(page);
+ try {
+ expect(await list.evaluate((element) => element.scrollHeight > element.clientHeight)).toBe(true);
+ for (let attempt = 0; attempt < 20; attempt += 1) {
+ const bounds = (await list.boundingBox())!;
+ const target = (await last.boundingBox())!;
+ if (target.y >= bounds.y && target.y + target.height <= bounds.y + bounds.height) break;
+ const before = await list.evaluate((element) => element.scrollTop);
+ const x = bounds.x + bounds.width / 2;
+ const y = bounds.y + bounds.height - 20;
+ const distance = Math.min(180, bounds.height - 40);
+ await session.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] });
+ for (let step = 1; step <= 12; step += 1) {
+ await session.send("Input.dispatchTouchEvent", {
+ type: "touchMove", touchPoints: [{ x, y: y - distance * step / 12 }],
+ });
+ // Pace native finger movement across compositor frames.
+ await page.waitForTimeout(20);
+ }
+ await session.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
+ await expect.poll(() => list.evaluate((element) => element.scrollTop)).toBeGreaterThan(before);
+ // A drag must not choose a row or dismiss the picker.
+ await expect(picker).toBeVisible();
+ }
+ const bounds = (await list.boundingBox())!;
+ const target = (await last.boundingBox())!;
+ expect(target.y).toBeGreaterThanOrEqual(bounds.y);
+ expect(target.y + target.height).toBeLessThanOrEqual(bounds.y + bounds.height + 1);
+ } finally {
+ await session.detach();
+ }
+ return last;
+}
+
+test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true });
+
+test("new-task assignee and model sheets scroll by touch and retain the selected values", async ({ page, request, browserName }, testInfo) => {
+ test.skip(browserName !== "chromium", "Native touch drags use Chromium's input protocol.");
+ const company = await json(await request.post("/api/companies", {
+ data: { name: `Touch pickers ${randomUUID()}` },
+ }));
+ for (let index = 1; index <= 22; index += 1) {
+ await json(await request.post(`/api/companies/${company.id}/agents`, {
+ data: {
+ name: `Touch Agent ${String(index).padStart(2, "0")}`, role: "engineer",
+ adapterType: "codex_local", adapterConfig: { model: "gpt-6-sol" },
+ runtimeConfig: { heartbeat: { enabled: false } },
+ },
+ }));
+ }
+ // Keep the provider catalog deterministic; task UI, agents, and drafts are real.
+ await page.route(`**/api/companies/${company.id}/adapters/codex_local/models*`, (route) => route.fulfill({
+ json: Array.from({ length: 24 }, (_, index) => ({
+ id: `touch-model-${String(index + 1).padStart(2, "0")}`,
+ label: `Touch Model ${String(index + 1).padStart(2, "0")}`,
+ })),
+ }));
+ await page.goto(`/${company.issuePrefix}/dashboard`);
+ await page.getByRole("navigation", { name: "Mobile navigation" }).getByRole("button", { name: "New Task", exact: true }).tap();
+ await page.getByPlaceholder("Task title").fill("Keep this touch selection draft");
+ await page.getByRole("button", { name: "Assignee", exact: true }).tap();
+ const assignees = page.getByRole("dialog", { name: "Select assignee", exact: true });
+ const lastAssignee = await swipeToLastOption(page, assignees);
+ await expect(lastAssignee).toHaveText("Touch Agent 22");
+ await lastAssignee.tap();
+ // Assignee confirmation advances to the project picker.
+ await page.getByRole("dialog", { name: "Select project", exact: true }).getByRole("button", { name: "No project", exact: true }).tap();
+ await expect(page.getByRole("button", { name: "Touch Agent 22", exact: true })).toBeVisible();
+
+ await page.getByRole("button", { name: "Codex options", exact: true }).tap();
+ await page.getByRole("radio", { name: "Custom", exact: true }).tap();
+ await page.getByRole("button", { name: "Default model", exact: true }).tap();
+ // A reduced viewport exercises the space available when a phone keyboard opens.
+ await page.setViewportSize({ width: 390, height: 430 });
+ const models = page.getByRole("dialog", { name: "Default model", exact: true });
+ const lastModel = await swipeToLastOption(page, models);
+ await expect(lastModel).toHaveText("Touch Model 24");
+ await lastModel.tap();
+ await page.setViewportSize({ width: 390, height: 844 });
+ await expect(page.getByRole("button", { name: "Touch Model 24", exact: true })).toBeVisible();
+ await expect(page.getByPlaceholder("Task title")).toHaveValue("Keep this touch selection draft");
+
+ // Reopening and closing the nested modal must preserve the outer task draft.
+ await page.getByRole("button", { name: "Touch Model 24", exact: true }).tap();
+ await page.getByRole("button", { name: "Close selector", exact: true }).tap();
+ await expect(models).toBeHidden();
+ await expect(page.getByRole("button", { name: "Touch Model 24", exact: true })).toBeVisible();
+ await expect(page.getByRole("button", { name: "Touch Agent 22", exact: true })).toBeVisible();
+ await expect(page.getByRole("button", { name: "Create Task", exact: true })).toBeEnabled();
+ await page.getByRole("button", { name: "Touch Model 24", exact: true }).tap();
+ await page.getByPlaceholder("Search models...").press("Escape");
+ await expect(models).toBeHidden();
+ await expect(page.getByRole("button", { name: "Touch Model 24", exact: true })).toBeFocused();
+ await page.getByRole("button", { name: "Touch Model 24", exact: true }).tap();
+ await page.touchscreen.tap(4, 4);
+ await expect(models).toBeHidden();
+ await expect(page.getByPlaceholder("Task title")).toHaveValue("Keep this touch selection draft");
+ await page.screenshot({ path: testInfo.outputPath("selected-mobile-assignee-and-model.png") });
+
+ // The desktop popover keeps mouse opening and keyboard selection.
+ await page.setViewportSize({ width: 1280, height: 900 });
+ await page.getByRole("button", { name: "Touch Model 24", exact: true }).click();
+ await page.getByPlaceholder("Search models...").fill("Touch Model 01");
+ await page.getByPlaceholder("Search models...").press("Enter");
+ await expect(page.getByRole("button", { name: "Touch Model 01", exact: true })).toBeVisible();
+});
diff --git a/ui/src/components/InlineEntitySelector.test.tsx b/ui/src/components/InlineEntitySelector.test.tsx
index a219e98728..bf221d605d 100644
--- a/ui/src/components/InlineEntitySelector.test.tsx
+++ b/ui/src/components/InlineEntitySelector.test.tsx
@@ -3,6 +3,7 @@
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { Dialog, DialogContent, DialogTitle } from "./ui/dialog";
import { InlineEntitySelector } from "./InlineEntitySelector";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -32,6 +33,112 @@ describe("InlineEntitySelector", () => {
document.body.innerHTML = "";
});
+ it("allows touch scrolling in a mobile picker portalled outside a parent dialog", async () => {
+ window.matchMedia = vi.fn().mockImplementation((query: string) => ({
+ matches: query === "(max-width: 40rem)",
+ media: query,
+ addEventListener: vi.fn(),
+ removeEventListener: vi.fn(),
+ }));
+ const root = createRoot(container);
+ await act(() => {
+ root.render(
+ <Dialog defaultOpen>
+ <DialogContent aria-describedby={undefined}>
+ <DialogTitle>New task</DialogTitle>
+ <InlineEntitySelector
+ value=""
+ options={Array.from({ length: 20 }, (_, index) => ({ id: `agent-${index}`, label: `Agent ${index}` }))}
+ placeholder="Assignee"
+ noneLabel="No assignee"
+ searchPlaceholder="Search assignees..."
+ emptyMessage="No assignees found."
+ onChange={vi.fn()}
+ triggerTestId="nested-assignee-picker"
+ openOnFocus={false}
+ disablePortal
+ />
+ </DialogContent>
+ </Dialog>,
+ );
+ });
+ try {
+ await act(() => {
+ document.querySelector<HTMLButtonElement>("[data-testid=nested-assignee-picker]")!.click();
+ });
+ // Let both real Radix scroll locks install their document listeners.
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
+ const list = document.querySelector<HTMLElement>("[data-mobile-entity-picker-list]")!;
+ expect(list).not.toBeNull();
+ expect(document.querySelector("[data-slot=dialog-content]")!.contains(list)).toBe(false);
+ // jsdom has no layout; supply the geometry of a list with more rows than fit.
+ list.style.overflowY = "auto";
+ Object.defineProperties(list, {
+ scrollHeight: { configurable: true, value: 1000 },
+ clientHeight: { configurable: true, value: 200 },
+ });
+ const option = list.querySelector("button")!;
+ const touch = (type: string, y: number) => {
+ const event = new Event(type, { bubbles: true, cancelable: true });
+ Object.defineProperties(event, {
+ touches: { value: [{ clientX: 100, clientY: y }] },
+ changedTouches: { value: [{ clientX: 100, clientY: y }] },
+ });
+ option.dispatchEvent(event);
+ return event;
+ };
+ touch("touchstart", 150);
+ expect(touch("touchmove", 100).defaultPrevented).toBe(false);
+ // The background stays locked while the picker is open.
+ const outsideMove = new Event("touchmove", { bubbles: true, cancelable: true });
+ Object.defineProperties(outsideMove, {
+ touches: { value: [{ clientX: 100, clientY: 100 }] },
+ changedTouches: { value: [{ clientX: 100, clientY: 100 }] },
+ });
+ document.body.dispatchEvent(outsideMove);
+ expect(outsideMove.defaultPrevented).toBe(true);
+ } finally {
+ await act(() => root.unmount());
+ }
+ });
+
+ it("opens on the next keyboard focus after a desktop outside dismissal", async () => {
+ const root = createRoot(container);
+ await act(() => {
+ root.render(<>
+ <button type="button" data-testid="outside-picker">Outside</button>
+ <InlineEntitySelector
+ value=""
+ options={[{ id: "agent-1", label: "Agent One" }]}
+ placeholder="Assignee"
+ noneLabel="No assignee"
+ searchPlaceholder="Search assignees..."
+ emptyMessage="No assignees found."
+ onChange={vi.fn()}
+ triggerTestId="desktop-assignee-picker"
+ />
+ </>);
+ });
+ try {
+ const trigger = container.querySelector<HTMLButtonElement>("[data-testid=desktop-assignee-picker]")!;
+ const outside = container.querySelector<HTMLButtonElement>("[data-testid=outside-picker]")!;
+ await act(() => trigger.click());
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
+ await act(() => {
+ outside.dispatchEvent(new MouseEvent("pointerdown", { bubbles: true, cancelable: true }));
+ outside.focus();
+ outside.click();
+ });
+ await act(async () => { await new Promise((resolve) => setTimeout(resolve, 0)); });
+ expect(document.querySelector("[data-mobile-entity-picker]")).toBeNull();
+ expect(document.activeElement).toBe(outside);
+ await act(() => trigger.focus());
+ expect(document.querySelector("[data-mobile-entity-picker]")).not.toBeNull();
+ } finally {
+ await act(() => root.unmount());
+ }
+ });
+
it("keeps handled search navigation keys inside the popover", async () => {
const root = createRoot(container);
const onChange = vi.fn();
diff --git a/ui/src/components/InlineEntitySelector.tsx b/ui/src/components/InlineEntitySelector.tsx
index e7c62545a5..700b89bbc1 100644
--- a/ui/src/components/InlineEntitySelector.tsx
+++ b/ui/src/components/InlineEntitySelector.tsx
@@ -94,6 +94,7 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
const highlightedIndexRef = useRef(0);
const inputRef = useRef<HTMLInputElement>(null);
const shouldPreventCloseAutoFocusRef = useRef(false);
+ const suppressNextTriggerFocusRef = useRef(false);
const isPointerDownRef = useRef(false);
const allOptions = useMemo<InlineEntityOption[]>(() => {
@@ -139,6 +140,9 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
return (
<Popover
+ // Mobile sheets portal outside their parent dialog. Give the sheet its
+ // own scroll lock so the parent does not cancel touch drags in its list.
+ modal={mobileSelectorModal}
open={open}
onOpenChange={(next) => {
if (disabled) return;
@@ -160,8 +164,9 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
onPointerDown={() => { isPointerDownRef.current = true; }}
onFocus={() => {
if (disabled) return;
- if (openOnFocus && !isPointerDownRef.current) setOpen(true);
+ if (openOnFocus && !isPointerDownRef.current && !suppressNextTriggerFocusRef.current) setOpen(true);
isPointerDownRef.current = false;
+ suppressNextTriggerFocusRef.current = false;
}}
>
{renderTriggerValue
@@ -183,7 +188,15 @@ export const InlineEntitySelector = forwardRef<HTMLButtonElement, InlineEntitySe
inputRef.current?.focus();
}}
onCloseAutoFocus={(event) => {
- if (!shouldPreventCloseAutoFocusRef.current) return;
+ if (!shouldPreventCloseAutoFocusRef.current) {
+ // Radix returns focus to the trigger on Escape/outside dismissal.
+ // That focus must not immediately reopen the picker.
+ suppressNextTriggerFocusRef.current = true;
+ // Non-modal outside dismissal may keep focus on the clicked
+ // element instead. Limit suppression to Radix's synchronous restore.
+ queueMicrotask(() => { suppressNextTriggerFocusRef.current = false; });
+ return;
+ }
event.preventDefault();
shouldPreventCloseAutoFocusRef.current = false;
}}