Skip to content

Commit bb5abef

Browse files
authored
fix: smooth chat focus mode layout
Collapse the focused chat chrome, suppress focused-mode header scroll churn, and seed the mock chat UI with enough history to exercise scrolling.
1 parent b745082 commit bb5abef

9 files changed

Lines changed: 162 additions & 26 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Docs: https://docs.openclaw.ai
5757
- QA-Lab/Codex: bundle auth/plugin fixture imports for flow scenarios and let terminal async media tools end Codex app-server turns without timing out. (#80397, refs #80323) Thanks @100yenadmin.
5858
- Gateway/agents: preserve fresh session overrides and metadata when stale cached agent-session entries race with store updates, so subagent model/provider overrides and routing policy survive concurrent writes. (#19328) Thanks @CodeReclaimers.
5959
- Control UI/chat: keep chat session search inline with the session selector so the header no longer shows a duplicate standalone search row.
60+
- Control UI/chat: collapse focused-mode header chrome and suppress hidden-header scroll updates so focus mode no longer jumps while scrolling. Thanks @amknight.
6061
- Codex app-server: restart the native app-server and retry once when server-side compaction times out, so preflight compaction stalls recover instead of failing every dispatch. (#85500)
6162
- Restore Control UI gateway token pairing [AI]. (#85459) Thanks @pgondhi987.
6263
- OpenAI video: honor configured provider request private-network opt-in for local/custom video endpoints so explicitly trusted mock and self-hosted providers are not blocked. Thanks @shakkernerd.

‎scripts/control-ui-mock-dev.ts‎

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,44 @@ function buildSearchSessionListCases(
146146
return searchTerms.flatMap((search) => buildSessionListCases(sessions, { search }));
147147
}
148148

149+
function chatHistoryMessage(role: "assistant" | "user", text: string, timestamp: number) {
150+
return {
151+
content: [{ text, type: "text" }],
152+
role,
153+
timestamp,
154+
};
155+
}
156+
157+
function buildScrollableChatHistory(baseTime: number): unknown[] {
158+
const messages: unknown[] = [
159+
chatHistoryMessage(
160+
"assistant",
161+
`Mock Control UI is running with ${TOTAL_MOCK_SESSIONS} sessions. Open the chat picker, search for "telegram" or "claude", then use Load more repeatedly.`,
162+
baseTime,
163+
),
164+
];
165+
166+
for (let index = 1; index <= 36; index += 1) {
167+
const timestamp = baseTime + index * 60_000;
168+
messages.push(
169+
chatHistoryMessage(
170+
"user",
171+
`Mock scroll request ${index}: add enough transcript content to exercise the chat scroll container in focused mode.`,
172+
timestamp,
173+
),
174+
chatHistoryMessage(
175+
"assistant",
176+
`Mock scroll response ${index}: this deterministic history keeps the mock chat long enough to scroll while testing focus mode, header collapse, and composer anchoring. `.repeat(
177+
2,
178+
),
179+
timestamp + 30_000,
180+
),
181+
);
182+
}
183+
184+
return messages;
185+
}
186+
149187
function searchPrefixes(term: string): string[] {
150188
return Array.from({ length: term.length }, (_value, index) => term.slice(0, index + 1));
151189
}
@@ -179,18 +217,7 @@ function createChatPickerScenario(): ControlUiMockGatewayScenario {
179217
assistantAgentId: "openclaw-mock",
180218
assistantName: "OpenClaw mock",
181219
defaultAgentId: "openclaw-mock",
182-
historyMessages: [
183-
{
184-
content: [
185-
{
186-
text: `Mock Control UI is running with ${TOTAL_MOCK_SESSIONS} sessions. Open the chat picker, search for "telegram" or "claude", then use Load more repeatedly.`,
187-
type: "text",
188-
},
189-
],
190-
role: "assistant",
191-
timestamp: baseTime,
192-
},
193-
],
220+
historyMessages: buildScrollableChatHistory(baseTime),
194221
methodResponses: {
195222
"sessions.list": {
196223
cases: [

‎ui/src/styles/layout.css‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
"nav content";
2020
gap: 0;
2121
animation: dashboard-enter 0.3s var(--ease-out);
22-
transition: grid-template-columns var(--shell-focus-duration) var(--shell-focus-ease);
22+
transition:
23+
grid-template-columns var(--shell-focus-duration) var(--shell-focus-ease),
24+
grid-template-rows var(--shell-focus-duration) var(--shell-focus-ease);
2325
overflow: hidden;
2426
}
2527

@@ -47,6 +49,7 @@
4749

4850
.shell--chat-focus {
4951
grid-template-columns: 0px minmax(0, 1fr);
52+
grid-template-rows: 0 minmax(0, 1fr);
5053
}
5154

5255
.shell--onboarding {
@@ -74,6 +77,17 @@
7477
margin-top: 0;
7578
}
7679

80+
.shell--chat-focus .topbar {
81+
min-height: 0;
82+
height: 0;
83+
padding-top: 0;
84+
padding-bottom: 0;
85+
overflow: hidden;
86+
opacity: 0;
87+
pointer-events: none;
88+
border-bottom-width: 0;
89+
}
90+
7791
/* ===========================================
7892
Topbar
7993
=========================================== */
@@ -1383,6 +1397,10 @@
13831397

13841398
.shell--chat-focus .content--chat .content-header {
13851399
min-height: 0;
1400+
max-height: 0;
1401+
padding-top: 0;
1402+
padding-bottom: 0;
1403+
overflow: hidden;
13861404
}
13871405

13881406
.content--chat .page-meta {

‎ui/src/styles/layout.mobile.css‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
row-gap: 0;
3333
}
3434

35+
.shell--chat-focus .content--chat .content-header {
36+
min-height: 0;
37+
max-height: 0;
38+
padding-top: 0;
39+
padding-bottom: 0;
40+
overflow: hidden;
41+
}
42+
3543
.chat-controls__session-row {
3644
grid-template-columns:
3745
minmax(96px, 5fr) minmax(112px, 7fr) minmax(116px, 5fr)
@@ -112,7 +120,7 @@
112120
}
113121

114122
.shell--chat-focus {
115-
grid-template-rows: var(--shell-topbar-height) minmax(0, 1fr);
123+
grid-template-rows: 0 minmax(0, 1fr);
116124
}
117125

118126
.shell-nav,

‎ui/src/styles/layout.mobile.test.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,38 @@ describe("chat header responsive mobile styles", () => {
5555
expect(css).toContain("width: 44px;");
5656
expect(css).toContain("min-width: 44px;");
5757
});
58+
59+
it("keeps focused chat from reserving hidden page-header height", () => {
60+
const layoutCss = readLayoutCss();
61+
const mobileCss = readMobileCss();
62+
const focusedShell = selectorBlocks(layoutCss, ".shell--chat-focus").join("\n");
63+
const focusedMobileShell = selectorBlocks(mobileCss, ".shell--chat-focus").join("\n");
64+
const focusedTopbar = selectorBlocks(layoutCss, ".shell--chat-focus .topbar").join("\n");
65+
const focusedHeaderSelector = ".shell--chat-focus .content--chat .content-header";
66+
const expectedDeclarations = [
67+
"min-height: 0;",
68+
"max-height: 0;",
69+
"padding-top: 0;",
70+
"padding-bottom: 0;",
71+
"overflow: hidden;",
72+
];
73+
74+
expect(focusedShell).toContain("grid-template-rows: 0 minmax(0, 1fr);");
75+
expect(focusedMobileShell).toContain("grid-template-rows: 0 minmax(0, 1fr);");
76+
expect(focusedTopbar).toContain("min-height: 0;");
77+
expect(focusedTopbar).toContain("height: 0;");
78+
expect(focusedTopbar).toContain("padding-top: 0;");
79+
expect(focusedTopbar).toContain("padding-bottom: 0;");
80+
expect(focusedTopbar).toContain("overflow: hidden;");
81+
82+
for (const css of [layoutCss, mobileCss]) {
83+
const block = selectorBlocks(css, focusedHeaderSelector).join("\n");
84+
expect(block).toBeTruthy();
85+
for (const declaration of expectedDeclarations) {
86+
expect(block).toContain(declaration);
87+
}
88+
}
89+
});
5890
});
5991

6092
describe("sidebar menu trigger styles", () => {

‎ui/src/ui/app-render.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ export function renderApp(state: AppViewState) {
910910
const chatDisabledReason = state.connected ? null : t("chat.disconnected");
911911
const isChat = state.tab === "chat";
912912
const chatFocus = isChat && (state.settings.chatFocusMode || state.onboarding);
913+
const chatHeaderHidden = isChat && (chatFocus || state.chatHeaderControlsHidden);
913914
const navDrawerOpen = state.navDrawerOpen && !chatFocus && !state.onboarding;
914915
const navCollapsed = state.settings.navCollapsed && !navDrawerOpen;
915916
const dashboardHeaderContext = resolveDashboardHeaderContext(state);
@@ -1678,7 +1679,7 @@ export function renderApp(state: AppViewState) {
16781679
state.navDrawerOpen = false;
16791680
}}
16801681
></button>
1681-
<header class="topbar">
1682+
<header class="topbar" ?inert=${chatFocus} aria-hidden=${chatFocus ? "true" : nothing}>
16821683
<div class="topnav-shell">
16831684
<button
16841685
type="button"
@@ -1871,11 +1872,11 @@ export function renderApp(state: AppViewState) {
18711872
${state.tab === "config"
18721873
? nothing
18731874
: html`<section
1874-
class=${isChat && state.chatHeaderControlsHidden
1875+
class=${chatHeaderHidden
18751876
? "content-header content-header--chat-hidden"
18761877
: "content-header"}
1877-
?inert=${isChat && state.chatHeaderControlsHidden}
1878-
aria-hidden=${isChat && state.chatHeaderControlsHidden ? "true" : nothing}
1878+
?inert=${chatHeaderHidden}
1879+
aria-hidden=${chatHeaderHidden ? "true" : nothing}
18791880
>
18801881
<div>
18811882
${isChat

‎ui/src/ui/app-scroll.test.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ function createScrollHost(
3636
overflowY,
3737
} as unknown as CSSStyleDeclaration);
3838

39+
const settings: { chatAutoScroll?: ChatAutoScrollMode; chatFocusMode?: boolean } = {};
40+
if (chatAutoScroll) {
41+
settings.chatAutoScroll = chatAutoScroll;
42+
}
43+
3944
const host = {
4045
updateComplete: Promise.resolve(),
4146
querySelector: vi.fn().mockReturnValue(container),
@@ -49,7 +54,7 @@ function createScrollHost(
4954
chatNewMessagesBelow: false,
5055
chatIsProgrammaticScroll: false,
5156
chatProgrammaticScrollTarget: 0,
52-
settings: chatAutoScroll ? { chatAutoScroll } : undefined,
57+
settings,
5358
logsScrollFrame: null as number | null,
5459
logsAtBottom: true,
5560
topbarObserver: null as ResizeObserver | null,
@@ -141,6 +146,25 @@ describe("handleChatScroll", () => {
141146

142147
expect(host.chatHeaderControlsHidden).toBe(false);
143148
});
149+
150+
it("does not toggle header controls while focus mode handles hidden chrome", () => {
151+
const { host } = createScrollHost({});
152+
host.settings = { ...host.settings, chatFocusMode: true };
153+
host.chatLastScrollTop = 100;
154+
host.chatHeaderControlsHidden = false;
155+
156+
handleChatScroll(host, createScrollEvent(3000, 260, 500));
157+
158+
expect(host.chatHeaderControlsHidden).toBe(false);
159+
expect(host.chatUserNearBottom).toBe(false);
160+
161+
host.chatHeaderControlsHidden = true;
162+
host.chatLastScrollTop = 800;
163+
164+
handleChatScroll(host, createScrollEvent(3000, 700, 500));
165+
166+
expect(host.chatHeaderControlsHidden).toBe(true);
167+
});
144168
});
145169

146170
/* ------------------------------------------------------------------ */

‎ui/src/ui/app-scroll.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type ScrollHost = {
2020
chatProgrammaticScrollTarget: number;
2121
settings?: {
2222
chatAutoScroll?: ChatAutoScrollMode;
23+
chatFocusMode?: boolean;
2324
};
2425
logsScrollFrame: number | null;
2526
logsAtBottom: boolean;
@@ -187,12 +188,14 @@ export function handleChatScroll(host: ScrollHost, event: Event) {
187188
host.chatUserNearBottom = distanceFromBottom < NEAR_BOTTOM_THRESHOLD;
188189
const hasUsefulScroll = container.scrollHeight - container.clientHeight > NEAR_BOTTOM_THRESHOLD;
189190

190-
if (!hasUsefulScroll || scrollTop <= HEADER_SHOW_TOP_THRESHOLD || host.chatUserNearBottom) {
191-
host.chatHeaderControlsHidden = false;
192-
} else if (delta > HEADER_HIDE_SCROLL_DELTA) {
193-
host.chatHeaderControlsHidden = true;
194-
} else if (delta < -HEADER_HIDE_SCROLL_DELTA) {
195-
host.chatHeaderControlsHidden = false;
191+
if (!host.settings?.chatFocusMode) {
192+
if (!hasUsefulScroll || scrollTop <= HEADER_SHOW_TOP_THRESHOLD || host.chatUserNearBottom) {
193+
host.chatHeaderControlsHidden = false;
194+
} else if (delta > HEADER_HIDE_SCROLL_DELTA) {
195+
host.chatHeaderControlsHidden = true;
196+
} else if (delta < -HEADER_HIDE_SCROLL_DELTA) {
197+
host.chatHeaderControlsHidden = false;
198+
}
196199
}
197200

198201
// Clear the "new messages below" indicator when user scrolls back to bottom.

‎ui/src/ui/navigation.browser.test.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,9 @@ describe("control UI routing", () => {
466466

467467
expect([...section.classList]).toContain("nav-section--collapsed");
468468
expect(
469-
section.querySelector<HTMLButtonElement>(".nav-section__label")?.getAttribute("aria-expanded"),
469+
section
470+
.querySelector<HTMLButtonElement>(".nav-section__label")
471+
?.getAttribute("aria-expanded"),
470472
).toBe("false");
471473
});
472474

@@ -609,26 +611,46 @@ describe("control UI routing", () => {
609611
expect(window.location.search).toBe("?session=agent%3Amain%3Asubagent%3Atask-123");
610612

611613
const shell = expectElement(app, ".shell", HTMLElement);
614+
const topbar = expectElement(app, ".topbar", HTMLElement);
615+
const contentHeader = expectElement(app, ".content-header", HTMLElement);
612616
expect([...shell.classList]).toEqual(["shell", "shell--chat"]);
617+
expect(topbar.hasAttribute("inert")).toBe(false);
618+
expect(topbar.hasAttribute("aria-hidden")).toBe(false);
619+
expect(contentHeader.hasAttribute("inert")).toBe(false);
620+
expect(contentHeader.hasAttribute("aria-hidden")).toBe(false);
613621

614622
const toggle = expectElement(app, 'button[title^="Toggle focus mode"]', HTMLButtonElement);
615623
toggle.click();
616624

617625
await app.updateComplete;
618626
expect([...shell.classList]).toEqual(["shell", "shell--chat", "shell--chat-focus"]);
627+
expect(topbar.hasAttribute("inert")).toBe(true);
628+
expect(topbar.getAttribute("aria-hidden")).toBe("true");
629+
expect(contentHeader.hasAttribute("inert")).toBe(true);
630+
expect(contentHeader.getAttribute("aria-hidden")).toBe("true");
619631

620632
app.setTab("channels");
621633

622634
await app.updateComplete;
623635
expect(app.tab).toBe("channels");
624636
expect([...shell.classList]).toEqual(["shell"]);
637+
expect(topbar.hasAttribute("inert")).toBe(false);
638+
expect(topbar.hasAttribute("aria-hidden")).toBe(false);
639+
const channelsContentHeader = expectElement(app, ".content-header", HTMLElement);
640+
expect(channelsContentHeader.hasAttribute("inert")).toBe(false);
641+
expect(channelsContentHeader.hasAttribute("aria-hidden")).toBe(false);
625642

626643
const chatLink = expectElement(app, 'a.nav-item[href="/chat"]', HTMLAnchorElement);
627644
chatLink.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true, button: 0 }));
628645

629646
await app.updateComplete;
630647
expect(app.tab).toBe("chat");
631648
expect([...shell.classList]).toEqual(["shell", "shell--chat", "shell--chat-focus"]);
649+
expect(topbar.hasAttribute("inert")).toBe(true);
650+
expect(topbar.getAttribute("aria-hidden")).toBe("true");
651+
const focusedContentHeader = expectElement(app, ".content-header", HTMLElement);
652+
expect(focusedContentHeader.hasAttribute("inert")).toBe(true);
653+
expect(focusedContentHeader.getAttribute("aria-hidden")).toBe("true");
632654
});
633655

634656
it("auto-scrolls chat history to the latest message", async () => {

0 commit comments

Comments
 (0)