fix(webui): adapt chat toolbar to available width (#5760)

* fix(webui): float chat controls above the transcript

* fix(webui): keep floating controls compact and flat

* fix(webui): adapt toolbar placement to conversation width

* refactor(webui): simplify responsive toolbar styles
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-14 15:25:13 +08:00
1 parent 95b2346ea5
commit f611c880f9
6 files changed
+67 -24

No files matched your search

+16 -7
View File
@@ -13,6 +13,12 @@ import {
import { cn } from "@/lib/utils";
import type { SessionHandle } from "@/lib/types";
const controlsClassName = cn(
"pointer-events-auto flex items-center gap-0.5 rounded-compact bg-background p-px empty:hidden",
"[&_button]:h-7 [&_button]:w-7 [&_button>svg]:h-3.5 [&_button>svg]:w-3.5",
"forced-colors:bg-[Canvas] forced-colors:outline forced-colors:outline-1 forced-colors:outline-[ButtonText]",
);
interface ThreadHeaderProps {
title: string;
handle?: SessionHandle | null;
@@ -56,11 +62,18 @@ export function ThreadHeader({
<div
data-testid="thread-header"
className={cn(
"relative z-30 flex items-center justify-between gap-3 px-3 py-1",
"pointer-events-none inset-x-0 top-0 z-30 flex shrink-0 items-center justify-between gap-3 px-3 py-1",
"[position:var(--thread-header-position,absolute)]",
minimal && "h-11",
)}
>
<div className="relative flex min-w-0 items-center gap-2">
<div
className={cn(
controlsClassName,
"relative min-w-0",
hideSidebarToggleForHostChrome && (minimal || hideTitle) && !handle && "lg:hidden",
)}
>
{!hideSidebarToggle ? (
<Button
variant="ghost"
@@ -91,7 +104,7 @@ export function ThreadHeader({
) : null}
</div>
<div className="ml-auto flex shrink-0 items-center gap-1">
<div className={cn(controlsClassName, "ml-auto shrink-0")}>
{sessionInfoAction}
{promptNavigatorAction}
{actions}
@@ -151,10 +164,6 @@ export function ThreadHeader({
/>
) : null}
</div>
{!minimal ? (
<div aria-hidden className="pointer-events-none absolute inset-x-0 top-full h-4" />
) : null}
</div>
);
}
+5 -1
View File
@@ -55,6 +55,7 @@ import type {
} from "@/lib/types";
import { projectWebuiThreadMessages } from "@/lib/thread-display-compat";
import { ThreadMessageCache } from "@/lib/thread-message-cache";
import { cn } from "@/lib/utils";
import { useClient } from "@/providers/ClientProvider";
type MessageShape = Pick<UIMessage, "role" | "kind" | "content" | "isStreaming" | "turnId">;
@@ -1693,7 +1694,10 @@ export function ThreadShell({
return (
<section ref={shellRef} className="relative flex min-h-0 flex-1 overflow-hidden">
<div className="relative flex min-w-0 flex-1 flex-col overflow-hidden">
<div className={cn(
"relative flex min-w-0 flex-1 flex-col overflow-hidden",
headerPortalTarget === undefined && !hideHeader && "thread-workspace",
)}>
{hideHeaderTitle && inlineHandle && !temporary && session?.handle ? (
<div
aria-label={`Session @${session.handle.name}`}
@@ -64,6 +64,7 @@ interface ThreadViewportProps {
}
const NEAR_BOTTOM_PX = 48;
const PROMPT_TOP_INSET_PX = 48;
const HISTORY_PREFETCH_MIN_PX = 160;
const HISTORY_PREFETCH_MAX_PX = 480;
const DEFAULT_SCROLL_BUTTON_BOTTOM_PX = 192;
@@ -83,6 +84,11 @@ interface HistoryScrollAnchor {
const THREAD_DISPLAY_UNIT_SELECTOR = "[data-thread-display-unit]";
function promptTopInset(scroller: HTMLElement): number {
const padding = Number.parseFloat(getComputedStyle(scroller).paddingTop);
return Number.isFinite(padding) ? padding : PROMPT_TOP_INSET_PX;
}
function historyPrefetchDistance(scroller: HTMLElement): number {
return Math.min(
HISTORY_PREFETCH_MAX_PX,
@@ -297,7 +303,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
promptTop: prompt
? Math.min(
maxScrollTop,
Math.max(0, promptTop(scrollEl, prompt) - 16),
Math.max(0, promptTop(scrollEl, prompt) - promptTopInset(scrollEl)),
)
: null,
};
@@ -477,7 +483,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
threadMotionRef.current?.navigateHistoryTo(
Math.min(
maxScrollTop,
Math.max(0, promptTop(scrollEl, prompt) - 16),
Math.max(0, promptTop(scrollEl, prompt) - promptTopInset(scrollEl)),
),
);
return true;
@@ -871,7 +877,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
data-testid="thread-message-region"
className={cn(
"thread-message-viewport thread-viewport-scrollbar row-start-1 flex min-h-0 min-w-0 flex-col",
"scroll-auto justify-start overflow-x-hidden px-3 pb-0 pt-3 sm:px-4",
"scroll-auto justify-start overflow-x-hidden px-3 pb-0 pt-[var(--thread-prompt-inset,3rem)] sm:px-4",
"[overflow-anchor:none] [scrollbar-width:none]",
"[&::-webkit-scrollbar]:hidden",
hasVerticalOverflow ? "overflow-y-auto" : "overflow-hidden",
@@ -968,11 +974,6 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
{!hasMessages ? <div ref={bottomRef} aria-hidden className="h-px" /> : null}
</div>
<div
aria-hidden
className="pointer-events-none absolute inset-x-0 top-0 h-3 bg-gradient-to-b from-background to-transparent"
/>
{hasMessages ? (
<PromptRail
messages={visibleMessages}
@@ -685,11 +685,15 @@ export function PaneWorkbench({
return (
<section
aria-label={t("workbench.aria", { defaultValue: "Conversation workbench" })}
className="flex h-full min-h-0 flex-col overflow-hidden bg-background"
className={cn(
"thread-workspace relative flex h-full min-h-0 flex-col overflow-hidden bg-background",
chrome && displayedPanes.length > 1
&& "[--thread-header-position:relative] [--thread-prompt-inset:1rem]",
)}
>
<TooltipProvider>
{chrome ? (
<header className="shrink-0 bg-background">
<header className="pointer-events-none inset-x-0 top-0 z-30 shrink-0 [position:var(--thread-header-position,absolute)]">
<div
ref={setHeaderPortalTarget}
data-testid="workbench-header-host"
+11
View File
@@ -604,6 +604,17 @@
}
}
.thread-workspace {
container: thread-workspace / inline-size;
}
/* Keep room for the 49.5rem message column and controls in the side margin. */
@container thread-workspace (max-width: 72rem) {
.thread-workspace > * {
--thread-header-position: relative;
--thread-prompt-inset: 1rem;
}
}
.workbench-pane {
transform-origin: top left;
}
+20 -6
View File
@@ -279,7 +279,6 @@ describe("ThreadViewport", () => {
expect(messageRegion).toHaveClass("justify-start");
expect(messageRegion).not.toHaveClass("justify-end");
expect(messageRegion).toHaveClass("thread-message-viewport");
expect(messageRegion).toHaveClass("pt-3");
expect(messageRegion).toHaveClass("pb-0");
expect(messageRegion.className).not.toContain("5rem");
});
@@ -573,7 +572,7 @@ describe("ThreadViewport", () => {
});
await flushAnimationFrame();
expect(jumpTo).toHaveBeenCalledWith(1404);
expect(jumpTo).toHaveBeenCalledWith(1372);
});
it("drives the camera from a message commit when canonical replay replaces the prompt DOM id", async () => {
@@ -1681,7 +1680,7 @@ describe("ThreadViewport", () => {
fireEvent.click(targetPrompt);
expect(navigateTo).toHaveBeenCalledWith(1064);
expect(navigateTo).toHaveBeenCalledWith(1032);
});
it("renders markdown in prompt rail previews", async () => {
@@ -1855,14 +1854,29 @@ describe("ThreadViewport", () => {
expect(markers).toHaveLength(count);
markers.forEach((marker, index) => {
fireEvent.click(marker);
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 16));
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, index * 40 - 48));
});
} else {
expect(markers.length).toBeGreaterThan(1);
expect(markers.length).toBeLessThan(count);
}
fireEvent.click(markers[markers.length - 1]);
expect(navigateTo).toHaveBeenLastCalledWith((count - 1) * 40 - 16);
expect(navigateTo).toHaveBeenLastCalledWith(Math.max(0, (count - 1) * 40 - 48));
});
it("keeps prompt jumps aligned when the header changes between a row and an overlay", async () => {
const navigateTo = vi.spyOn(ThreadCameraController.prototype, "navigateTo")
.mockReturnValue("started");
const { scroller } = await renderPromptRailViewport();
const marker = screen.getByRole("button", { name: "Jump to prompt: message 1" });
scroller.style.paddingTop = "16px";
fireEvent.click(marker);
expect(navigateTo).toHaveBeenLastCalledWith(344);
scroller.style.paddingTop = "48px";
fireEvent.click(marker);
expect(navigateTo).toHaveBeenLastCalledWith(312);
});
it("buckets dense prompt rails without rendering every prompt as a marker", async () => {
@@ -1913,7 +1927,7 @@ describe("ThreadViewport", () => {
fireEvent.click(promptMarkers[promptMarkers.length - 1]);
expect(navigateTo).toHaveBeenCalledWith(8894);
expect(navigateTo).toHaveBeenCalledWith(8862);
});
it("expands the window start to avoid cutting an agent activity cluster", () => {