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): fit session search above the mobile keyboard
Xubin Ren2442d88b91cc
diff --git a/docs/webui.md b/docs/webui.mdindex 87c297e28..dc7fb814d 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -190,7 +190,9 @@ does not proxy pages or bypass those restrictions; use **Open in browser** insteOn touch devices with Visual Viewport support, the app follows the visible areawhen the on-screen keyboard opens or pans the page. Navigation and the composer-stay in view while messages scroll independently. The `@` mention and `/` command+stay in view while messages scroll independently. Session search also follows+the visible area: the search field stays above the keyboard and results scroll+inside the dialog. 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 6692c97a6..0da4a277a 100644--- a/webui/src/components/SessionSearchDialog.tsx+++ b/webui/src/components/SessionSearchDialog.tsx@@ -140,7 +140,7 @@ export function SessionSearchDialog({<DialogContentshowCloseButton={false}className={cn(- "flex max-h-[min(40rem,calc(100vh-2rem))] w-[calc(100vw-2rem)] max-w-[42rem] flex-col gap-0 overflow-hidden p-0",+ "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>diff --git a/webui/src/components/ui/dialog.tsx b/webui/src/components/ui/dialog.tsxindex 02773a88d..4d4232682 100644--- a/webui/src/components/ui/dialog.tsx+++ b/webui/src/components/ui/dialog.tsx@@ -41,7 +41,12 @@ 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={positionerStyle}>+ <div className={cn("fixed inset-0 z-50 flex justify-center", placement === "bottom" ? "items-end" : "items-center p-4")} style={{+ top: "var(--app-viewport-top, 0px)",+ height: "var(--app-viewport-height, 100%)",+ bottom: "auto",+ ...positionerStyle,+ }}><DialogPrimitive.Content ref={ref} {...props} /></div>));diff --git a/webui/src/hooks/useAppViewport.ts b/webui/src/hooks/useAppViewport.tsindex c833724a4..5493ef77b 100644--- a/webui/src/hooks/useAppViewport.ts+++ b/webui/src/hooks/useAppViewport.ts@@ -9,15 +9,17 @@ export function useAppViewport() {const viewport = window.visualViewport;const root = document.getElementById("root");if (!touch || !viewport || !root || isNativeRuntime()) return;+ // Body portals (for example session search) share the app's viewport owner.+ const viewportStyle = document.documentElement.style;const update = () => {// Pinch zoom pans the existing layout; it must not reflow it or chase the// user's magnified viewport. Resume fitting when the scale returns to 1.if (viewport.scale !== 1) return;- root.style.setProperty("--app-viewport-height", `${viewport.height}px`);+ viewportStyle.setProperty("--app-viewport-height", `${viewport.height}px`);// WebKit can report a negative offset after rotating a focused PWA.// Do not move the navigation above the top edge with that overscroll.- root.style.setProperty("--app-viewport-top", `${Math.max(0, viewport.offsetTop)}px`);+ viewportStyle.setProperty("--app-viewport-top", `${Math.max(0, viewport.offsetTop)}px`);root.classList.add("visual-viewport");// Only the keyboard's shortest layouts need a scrollable composer.// Normal layouts must let the command and mention palettes overflow.@@ -31,8 +33,8 @@ export function useAppViewport() {viewport.removeEventListener("scroll", update);root.classList.remove("visual-viewport");root.classList.remove("short-visual-viewport");- root.style.removeProperty("--app-viewport-height");- root.style.removeProperty("--app-viewport-top");+ viewportStyle.removeProperty("--app-viewport-height");+ viewportStyle.removeProperty("--app-viewport-top");};}, [touch]);}diff --git a/webui/src/tests/session-search-dialog.test.tsx b/webui/src/tests/session-search-dialog.test.tsxindex e007caceb..deaf40963 100644--- a/webui/src/tests/session-search-dialog.test.tsx+++ b/webui/src/tests/session-search-dialog.test.tsx@@ -48,6 +48,14 @@ describe("SessionSearchDialog", () => {expect(dialog).toHaveClass("bg-background");expect(dialog.className).not.toContain("bg-popover/");expect(dialog.className).not.toContain("backdrop-blur");+ // The body portal must share the app's keyboard-fitted frame. Its list+ // height is bounded by that frame, not by the layout viewport's 100vh.+ expect(dialog.parentElement).toHaveStyle({+ top: "var(--app-viewport-top, 0px)",+ height: "var(--app-viewport-height, 100%)",+ bottom: "auto",+ });+ expect(dialog).toHaveClass("max-h-[min(40rem,100%)]");expect(screen.getByTestId("session-search-scroll")).toHaveClass("overflow-y-auto");expect(screen.queryByText("/model fast")).not.toBeInTheDocument();fireEvent.change(screen.getByRole("textbox", { name: "Search" }), {diff --git a/webui/src/tests/useAppViewport.test.tsx b/webui/src/tests/useAppViewport.test.tsxindex bc9419aef..c6f17bd7b 100644--- a/webui/src/tests/useAppViewport.test.tsx+++ b/webui/src/tests/useAppViewport.test.tsx@@ -39,38 +39,38 @@ describe("app visual viewport", () => {input.focus();resize(396, 350);expect(root).toHaveClass("visual-viewport");- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("396px");- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("350px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("396px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("350px");act(() => {viewport.offsetTop = 320;viewport.dispatchEvent(new Event("scroll"));});- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("320px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("320px");expect(document.activeElement).toBe(input);expect(input).toHaveValue("中文草稿");resize(746, 0);- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("746px");- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("746px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");});it("does not reflow or chase the viewport during pinch zoom, then resumes on reset", () => {render(<AppSurface />, { container: root });resize(373, 120, 2);- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("746px");- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("746px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");resize(320, 0);- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("320px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("320px");});it("keeps navigation below the top edge when a focused PWA rotates with negative WebKit overscroll", () => {render(<AppSurface />, { container: root });resize(128, -68);expect(root).toHaveClass("short-visual-viewport");- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("128px");- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("0px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("128px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("0px");resize(428, 416);expect(root).not.toHaveClass("short-visual-viewport");- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("416px");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("416px");});it.each(["desktop", "native", "unsupported"])("leaves %s layout ownership unchanged", (kind) => {@@ -80,7 +80,7 @@ describe("app visual viewport", () => {render(<AppSurface />, { container: root });resize(396, 350);expect(root).not.toHaveClass("visual-viewport");- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("");});it("releases listeners and owned styles when touch layout is disabled or the app unmounts", () => {@@ -89,7 +89,7 @@ describe("app visual viewport", () => {rerender(<AppSurface />);resize(396, 350);expect(root).not.toHaveClass("visual-viewport");- expect(root.style.getPropertyValue("--app-viewport-height")).toBe("");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-height")).toBe("");touch = true;rerender(<AppSurface />);expect(root).toHaveClass("visual-viewport");@@ -97,6 +97,6 @@ describe("app visual viewport", () => {resize(746, 0);expect(root).not.toHaveClass("visual-viewport");expect(root).not.toHaveClass("short-visual-viewport");- expect(root.style.getPropertyValue("--app-viewport-top")).toBe("");+ expect(document.documentElement.style.getPropertyValue("--app-viewport-top")).toBe("");});});