Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
fix(webui): preserve search results and dialog scrolling with landscape keyboards
Xubin Rence89f7caf775
diff --git a/docs/webui.md b/docs/webui.mdindex dc7fb814d..ee7a2672e 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -192,7 +192,9 @@ On touch devices with Visual Viewport support, the app follows the visible areawhen the on-screen keyboard opens or pans the page. Navigation and the composerstay in view while messages scroll independently. Session search also followsthe visible area: the search field stays above the keyboard and results scroll-inside the dialog. The `@` mention and `/` command+inside the dialog. In short landscape viewports, its input and results sit side+by side so a result remains reachable. Taller dialogs scroll from their top+instead of centering content outside the visible area. The `@` mention and `/` commandmenus use the visible app area above or below the composer, including when thekeyboard pans the page. Scroll within a menu to reach more results. Mention rowsuse the app's larger touch targets on phones while retaining desktop density.diff --git a/webui/src/components/SessionSearchDialog.tsx b/webui/src/components/SessionSearchDialog.tsxindex 0da4a277a..5a4ff6cfa 100644--- a/webui/src/components/SessionSearchDialog.tsx+++ b/webui/src/components/SessionSearchDialog.tsx@@ -140,14 +140,14 @@ export function SessionSearchDialog({<DialogContentshowCloseButton={false}className={cn(- "flex max-h-[min(40rem,100%)] w-[calc(100vw-2rem)] max-w-[42rem] flex-col gap-0 overflow-hidden p-0",+ "session-search-dialog flex max-h-[min(40rem,100%)] w-[calc(100vw-2rem)] max-w-[42rem] flex-col gap-0 overflow-hidden p-0",)}><DialogTitle className="sr-only">{t("sidebar.searchAria")}</DialogTitle><DialogDescription className="sr-only">{t("sidebar.searchPlaceholder")}</DialogDescription>- <div className="flex h-[62px] shrink-0 items-center gap-3 border-b border-border px-[18px]">+ <div className="session-search-input flex h-[62px] shrink-0 items-center gap-3 border-b border-border px-[18px]"><SearchclassName="h-[18px] w-[18px] shrink-0 text-muted-foreground"aria-hidden@@ -170,7 +170,7 @@ export function SessionSearchDialog({className="min-h-0 flex-1 overflow-y-auto overscroll-contain p-2.5 scrollbar-thin scrollbar-track-transparent"><section>- <div className="px-2.5 pb-1.5 pt-1 text-[12px] font-medium text-muted-foreground">+ <div className="session-search-label px-2.5 pb-1.5 pt-1 text-[12px] font-medium text-muted-foreground">{sectionLabel}</div>diff --git a/webui/src/components/ui/dialog.tsx b/webui/src/components/ui/dialog.tsxindex 4d4232682..98fd1557c 100644--- a/webui/src/components/ui/dialog.tsx+++ b/webui/src/components/ui/dialog.tsx@@ -24,7 +24,7 @@ const DialogOverlay = React.forwardRef<ref={ref}className={cn(modalOverlayClassName,- "motion-reduce:animate-none",+ "duration-200 motion-reduce:animate-none",className,)}{...props}@@ -34,6 +34,8 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;// The portal's presence ref must reach the animated content, not the plain// positioning wrapper; otherwise the wrapper unmounts before the exit finishes.+// Auto margins center/bottom-align surfaces when they fit, but collapse to zero+// when they overflow so the beginning of a tall dialog remains scrollable.const DialogPositionedContent = React.forwardRef<React.ElementRef<typeof DialogPrimitive.Content>,React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {@@ -41,7 +43,7 @@ const DialogPositionedContent = React.forwardRef<placement?: "center" | "bottom";}>(({ positionerStyle, placement, ...props }, ref) => (- <div className={cn("fixed inset-0 z-50 flex justify-center", placement === "bottom" ? "items-end" : "items-center p-4")} style={{+ <div className={cn("fixed inset-0 z-50 flex items-start justify-center overflow-y-auto overscroll-contain", placement !== "bottom" && "p-4")} style={{top: "var(--app-viewport-top, 0px)",height: "var(--app-viewport-height, 100%)",bottom: "auto",@@ -97,7 +99,7 @@ const DialogContent = React.forwardRef<}, [ref]);return (<DialogPortal>- <DialogOverlay className={overlayClassName} />+ <DialogOverlay className={overlayClassName}><DialogPositionedContentpositionerStyle={layout}placement={placement}@@ -113,8 +115,8 @@ const DialogContent = React.forwardRef<modalSurfaceClassName,"relative grid w-full max-w-lg gap-4 p-6 duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 motion-reduce:animate-none",placement === "bottom"- ? "max-h-[85dvh] overflow-y-auto overscroll-contain rounded-t-modal pb-[max(1rem,env(safe-area-inset-bottom))] data-[state=open]:slide-in-from-bottom-4 data-[state=closed]:slide-out-to-bottom-4"- : "origin-center rounded-modal data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",+ ? "mt-auto max-h-[85dvh] overflow-y-auto overscroll-contain rounded-t-modal pb-[max(1rem,env(safe-area-inset-bottom))] data-[state=open]:slide-in-from-bottom-4 data-[state=closed]:slide-out-to-bottom-4"+ : "my-auto origin-center rounded-modal data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",className,)}{...props}@@ -129,6 +131,7 @@ const DialogContent = React.forwardRef<</DialogPrimitive.Close>) : null}</DialogPositionedContent>+ </DialogOverlay></DialogPortal>);});diff --git a/webui/src/globals.css b/webui/src/globals.cssindex 5d689dc43..94ad53d3b 100644--- a/webui/src/globals.css+++ b/webui/src/globals.css@@ -141,6 +141,25 @@overflow-y: auto;}+ /* Body portals share the viewport owner's short-frame state. A landscape+ keyboard needs input and results beside each other, not stacked. */+ @media (min-width: 640px) {+ body:has(> #root.short-visual-viewport) .session-search-dialog {+ flex-direction: row;+ }++ body:has(> #root.short-visual-viewport) .session-search-input {+ width: 40%;+ height: auto;+ border-bottom-width: 0;+ border-right-width: 1px;+ }++ body:has(> #root.short-visual-viewport) .session-search-label {+ @apply sr-only;+ }+ }+* {scrollbar-color: var(--scrollbar-thumb) transparent;scrollbar-width: thin;diff --git a/webui/src/tests/session-search-dialog.test.tsx b/webui/src/tests/session-search-dialog.test.tsxindex deaf40963..dcc83b44c 100644--- a/webui/src/tests/session-search-dialog.test.tsx+++ b/webui/src/tests/session-search-dialog.test.tsx@@ -1,7 +1,9 @@-import { fireEvent, render, screen } from "@testing-library/react";+import { useState } from "react";+import { act, cleanup, fireEvent, render, screen } from "@testing-library/react";import { afterEach, describe, expect, it, vi } from "vitest";import { SessionSearchDialog } from "@/components/SessionSearchDialog";+import { useAppViewport } from "@/hooks/useAppViewport";import type { ChatSummary } from "@/lib/types";function session(index: number): ChatSummary {@@ -29,9 +31,60 @@ describe("SessionSearchDialog", () => {expect(screen.getAllByRole("button").length).toBeLessThanOrEqual(24);});afterEach(() => {+ cleanup();+ vi.unstubAllGlobals();vi.restoreAllMocks();});+ it("shares keyboard rotation and dismissal with the body portal without losing a draft", () => {+ vi.stubGlobal("matchMedia", vi.fn(() => ({+ matches: true, addEventListener: vi.fn(), removeEventListener: vi.fn(),+ })));+ const viewport = Object.assign(new EventTarget(), { height: 428, offsetTop: 0, scale: 1 });+ vi.stubGlobal("visualViewport", viewport);+ const onSelect = vi.fn();+ function SearchApp() {+ useAppViewport();+ const [open, setOpen] = useState(true);+ return <>+ <textarea aria-label="Draft" defaultValue="Unsent draft" />+ <SessionSearchDialog open={open} sessions={[session(1), session(2)]}+ activeKey={null} loading={false} onOpenChange={setOpen} onSelect={onSelect} />+ </>;+ }+ const root = document.createElement("div");+ root.id = "root";+ document.body.append(root);+ const app = render(<SearchApp />, { container: root });+ try {+ const dialog = screen.getByRole("dialog");+ expect(root.contains(dialog)).toBe(false);+ act(() => {+ Object.assign(viewport, { height: 128, offsetTop: -68 });+ viewport.dispatchEvent(new Event("resize"));+ });+ expect(root).toHaveClass("short-visual-viewport");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("128px");+ expect(dialog).toHaveClass("session-search-dialog");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");+ act(() => {+ Object.assign(viewport, { height: 428, offsetTop: 0 });+ viewport.dispatchEvent(new Event("resize"));+ });+ expect(root).not.toHaveClass("short-visual-viewport");+ fireEvent.change(screen.getByRole("textbox", { name: "Search" }), { target: { value: "Chat 2" } });+ expect(screen.getAllByRole("button")).toHaveLength(1);+ fireEvent.click(screen.getByRole("button", { name: /Chat 2/ }));+ expect(onSelect).toHaveBeenCalledOnce();+ expect(onSelect).toHaveBeenCalledWith("websocket:chat-2");+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ expect(screen.getByRole("textbox", { name: "Draft" })).toHaveValue("Unsent draft");+ } finally {+ app.unmount();+ root.remove();+ }+ });+it("uses a solid compact command palette surface", () => {render(<SessionSearchDialogdiff --git a/webui/src/tests/ui-shape-system.test.tsx b/webui/src/tests/ui-shape-system.test.tsxindex 3f03f0231..a16c285d8 100644--- a/webui/src/tests/ui-shape-system.test.tsx+++ b/webui/src/tests/ui-shape-system.test.tsx@@ -24,6 +24,18 @@ import { Input } from "@/components/ui/input";import { Textarea } from "@/components/ui/textarea";describe("UI shape system", () => {+ it.each(["center", "bottom"] as const)("keeps an oversized %s dialog scrollable from its start", (placement) => {+ render(<Dialog open><DialogContent placement={placement}>+ <DialogTitle>Long dialog</DialogTitle>+ <DialogDescription>Content that can outgrow a keyboard-fitted frame.</DialogDescription>+ </DialogContent></Dialog>);+ const dialog = screen.getByRole("dialog");+ expect(dialog.parentElement).toHaveClass("items-start", "overflow-y-auto");+ // The scroll owner stays inside Radix's overlay/scroll-lock boundary.+ expect(dialog.parentElement?.parentElement).toHaveClass("backdrop-blur-[8px]", "duration-200");+ expect(dialog).toHaveClass(placement === "bottom" ? "mt-auto" : "my-auto");+ });+it("uses pill-shaped inputs and the shared radius for other controls", () => {render(<>