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): keep landscape suggestions beside the composer
Xubin Renfc729df9abe3
diff --git a/docs/webui.md b/docs/webui.mdindex 24f2a78d5..87c297e28 100644--- a/docs/webui.md+++ b/docs/webui.md@@ -194,9 +194,10 @@ stay in view while messages scroll independently. The `@` mention and `/` commanmenus 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.-In very short viewports (such-as landscape with the keyboard open), scroll within the composer to reach its-controls. If the browser bars and keyboard leave no usable page area, dismiss+In very short, wide viewports (such as landscape with the keyboard open), menus+sit beside the input instead of overflowing the scrollable composer. Scroll the+menu for more candidates and the input area for its controls. If the browser+bars and keyboard leave no usable page area, dismissthe keyboard or return to portrait. Pinch zoom keeps the existing layout instead of resizing it to themagnified area; normal fitting resumes whenyou return to the default zoom. Non-touch desktop and native-host layout remaindiff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsxindex 92fb23968..1eca1866b 100644--- a/webui/src/components/thread/ThreadComposer.tsx+++ b/webui/src/components/thread/ThreadComposer.tsx@@ -307,7 +307,7 @@ function VoiceRecordingMeter({);}-type SlashPalettePlacement = "above" | "below";+type SlashPalettePlacement = "above" | "below" | "beside";interface SlashPaletteLayout {placement: SlashPalettePlacement;@@ -1553,11 +1553,18 @@ export function ThreadComposer({const bounds = getVisibleBounds(form);const spaceAbove = Math.max(0, rect.top - bounds.top - SLASH_PALETTE_GAP_PX);const spaceBelow = Math.max(0, bounds.bottom - rect.bottom - SLASH_PALETTE_GAP_PX);+ // A landscape keyboard can leave less height than one input and option.+ // Use the available width instead of clipping an absolute menu in the+ // short viewport's scrollable composer footer.+ const beside = rect.width >= 640+ && !!form.closest("#root.short-visual-viewport");const placement: SlashPalettePlacement =- spaceAbove >= SLASH_PALETTE_MIN_HEIGHT_PX || spaceAbove >= spaceBelow+ beside ? "beside" : spaceAbove >= SLASH_PALETTE_MIN_HEIGHT_PX || spaceAbove >= spaceBelow? "above": "below";- const available = placement === "above" ? spaceAbove : spaceBelow;+ const available = beside+ ? Math.max(0, bounds.bottom - bounds.top)+ : placement === "above" ? spaceAbove : spaceBelow;const maxHeight = Math.min(SLASH_PALETTE_MAX_HEIGHT_PX, available);setSlashPaletteLayout((current) =>@@ -1573,7 +1580,10 @@ export function ThreadComposer({viewport?.addEventListener("scroll", updateLayout);window.addEventListener("resize", updateLayout);document.addEventListener("scroll", updateLayout, true);+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(updateLayout);+ if (formRef.current) observer?.observe(formRef.current);return () => {+ observer?.disconnect();viewport?.removeEventListener("resize", updateLayout);viewport?.removeEventListener("scroll", updateLayout);window.removeEventListener("resize", updateLayout);@@ -2360,11 +2370,13 @@ export function ThreadComposer({): "min-h-[50px] px-3.5 pb-1.5 pt-3 text-[16px] leading-5 sm:px-4",);+ const paletteBeside = showAnyPalette && slashPaletteLayout.placement === "beside";return (<formref={formRef}data-compact-controls={compactControls ? "true" : undefined}+ data-palette-beside={paletteBeside || undefined}onFocusCapture={() => {if (!compactWhenIdle) return;// Portaled model controls belong to this composer too: keep its layout@@ -2406,6 +2418,7 @@ export function ThreadComposer({"relative w-full",isHero ? "px-0" : "px-1 pb-1.5 pt-1 sm:px-0",compactWhenIdle && "thread-composer-collapsible-layout",+ paletteBeside && "grid grid-cols-2 items-start gap-2 p-0",)}>{showSlashMenu ? (@@ -2431,8 +2444,10 @@ export function ThreadComposer({<divref={surfaceRef}data-compact={compactIdle || undefined}+ style={paletteBeside ? { maxHeight: slashPaletteLayout.maxHeight, overflowY: "auto" } : undefined}className={cn("thread-composer-surface group/composer relative mx-auto flex w-full flex-col overflow-visible transition-all duration-200",+ paletteBeside && "col-start-1 row-start-1",isHero? "max-w-[58rem] rounded-prominent bg-muted/80 focus-within:bg-muted dark:bg-card dark:focus-within:bg-white/[0.06]": "max-w-[49.5rem] rounded-panel bg-muted/80 focus-within:bg-muted dark:bg-card dark:focus-within:bg-white/[0.06]",@@ -3072,8 +3087,11 @@ function CliAppMentionPalette({style={{ maxHeight: layout.maxHeight }}className={cn(floatingSurfaceVisualClassName,- "absolute left-1/2 z-30 w-[calc(100%-0.5rem)] -translate-x-1/2 overflow-hidden",- layout.placement === "above" ? "bottom-full mb-2" : "top-full mt-2",+ "z-30 overflow-hidden",+ layout.placement === "beside"+ ? "relative col-start-2 row-start-1 w-full"+ : cn("absolute left-1/2 w-[calc(100%-0.5rem)] -translate-x-1/2",+ layout.placement === "above" ? "bottom-full mb-2" : "top-full mt-2"),isHero ? "max-w-[58rem]" : "max-w-[49.5rem]",)}>@@ -3225,8 +3243,11 @@ function SlashCommandPalette({style={{ maxHeight: layout.maxHeight }}className={cn(floatingSurfaceVisualClassName,- "absolute left-1/2 z-30 w-[calc(100%-0.5rem)] -translate-x-1/2 overflow-hidden",- layout.placement === "above" ? "bottom-full mb-2" : "top-full mt-2",+ "z-30 overflow-hidden",+ layout.placement === "beside"+ ? "relative col-start-2 row-start-1 w-full"+ : cn("absolute left-1/2 w-[calc(100%-0.5rem)] -translate-x-1/2",+ layout.placement === "above" ? "bottom-full mb-2" : "top-full mt-2"),isHero ? "max-w-[58rem]" : "max-w-[49.5rem]",)}>diff --git a/webui/src/tests/thread-composer.test.tsx b/webui/src/tests/thread-composer.test.tsxindex 6d5636dd5..df76edf57 100644--- a/webui/src/tests/thread-composer.test.tsx+++ b/webui/src/tests/thread-composer.test.tsx@@ -2775,6 +2775,47 @@ describe("ThreadComposer", () => {expect(input).not.toHaveValue(trigger);});+ it.each(["/", "@"]) ("keeps %s selectable beside the input in a short landscape frame", (trigger) => {+ stubVisualViewport({ height: 128, offsetTop: 208 });+ let landscape = true;+ vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockImplementation(+ () => rect({ top: landscape ? 44 : 274, width: landscape ? 744 : 388, height: 112 }),+ );+ vi.spyOn(HTMLDivElement.prototype, "getBoundingClientRect").mockImplementation(function () {+ return this.id === "root"+ ? rect({ top: 0, width: landscape ? 776 : 420, height: landscape ? 128 : 396 })+ : rect({ top: landscape ? 44 : 0, width: landscape ? 776 : 420, height: landscape ? 84 : 396 });+ });+ const onSend = vi.fn();+ render(+ <div id="root" className="visual-viewport short-visual-viewport" style={{ overflowY: "hidden" }}>+ <div style={{ overflowY: "auto" }}>+ <ThreadComposer onSend={onSend} slashCommands={COMMANDS} cliApps={CLI_APPS} />+ </div>+ </div>,+ );+ const input = screen.getByLabelText("Message input");+ fireEvent.change(input, { target: { value: trigger, selectionStart: 1 } });+ const palette = screen.getByRole("listbox");+ expect(palette).toHaveClass("col-start-2");+ expect(palette).not.toHaveClass("absolute");+ expect(palette).toHaveStyle({ maxHeight: "84px" });+ expect(input.closest("form")).toHaveAttribute("data-palette-beside", "true");++ // Rotation restores the ordinary floating menu, without changing the draft.+ landscape = false;+ document.getElementById("root")!.classList.remove("short-visual-viewport");+ Object.assign(window.visualViewport!, { height: 396, offsetTop: 350 });+ act(() => window.visualViewport!.dispatchEvent(new Event("resize")));+ expect(palette).toHaveClass("bottom-full");+ expect(palette).toHaveStyle({ maxHeight: "266px" });+ expect(input).toHaveValue(trigger);+ fireEvent.mouseDown(screen.getAllByRole("option")[0]!);+ expect(screen.queryByRole("listbox")).not.toBeInTheDocument();+ expect(input.closest("form")).not.toHaveAttribute("data-palette-beside");+ expect(onSend).not.toHaveBeenCalled();+ });+it.each([false, true])("uses visual bounds outside fitting (pinch zoom: %s)", (zoomed) => {stubVisualViewport({ height: 300, offsetTop: 100 });if (zoomed) Object.assign(window.visualViewport!, { scale: 2 });