From fc729df9abe340e3fa32c63b2f89ec25207c3bdc Mon Sep 17 00:00:00 2001 From: Xubin Ren <52506698+Re-bin@users.noreply.github.com> Date: Sun, 4 Oct 2026 18:19:18 +0800 Subject: [PATCH] fix(webui): keep landscape suggestions beside the composer --- docs/webui.md | 7 ++-- .../src/components/thread/ThreadComposer.tsx | 35 ++++++++++++---- webui/src/tests/thread-composer.test.tsx | 41 +++++++++++++++++++ 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/docs/webui.md b/docs/webui.md index 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 `/` comman menus use the visible app area above or below the composer, including when the keyboard pans the page. Scroll within a menu to reach more results. Mention rows use 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, dismiss the keyboard or return to portrait. Pinch zoom keeps the existing layout instead of resizing it to the magnified area; normal fitting resumes when you return to the default zoom. Non-touch desktop and native-host layout remain diff --git a/webui/src/components/thread/ThreadComposer.tsx b/webui/src/components/thread/ThreadComposer.tsx index 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 (