Skip to content

Commit 9ce8ac9

Browse files
authored
feat(ui): fold the mobile navigation row into the chat title bar (#109635)
* feat(ui): fold the mobile navigation row into the chat title bar On plain-browser mobile layouts the chat route drops the 58px shell topbar; the pane title bar gains a leading nav-drawer toggle and a trailing command-palette search button (~50px more chat). The shared mobile-nav breakpoint moves into one module used by shell and chat; native shells and non-chat routes keep today's chrome. * improve(ui): anchor the workspace chip right after the session title The chip now hugs the title text with the header's standard gap instead of sitting at the far right; the action cluster claims the leftover width and stays right-pinned. Where field-sizing is supported the rename input hugs its text too, so the chip tracks the title while typing. * chore(ui): keep hasNativeShellClass module-local
1 parent ae40ce4 commit 9ce8ac9

13 files changed

Lines changed: 309 additions & 16 deletions

‎docs/web/control-ui.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ The **+** in the sidebar session-list header opens a full-page draft at `/new`:
181181

182182
Inside **Settings**, the dedicated sidebar starts with a **Search settings** field for quickly finding settings sections.
183183

184-
A **Search** field at the top of the sidebar opens the command palette (⌘K). Clicking the OpenClaw brand in the sidebar header opens the clean New session start screen. When something needs action — failed or overdue cron jobs, expiring or expired model auth — compact attention chips appear above the sidebar footer and click through to the owning page. The footer shows the active agent as a chip — avatar (identity image or emoji), name, connection dot, and a live subtitle — with a **+** for a new session. Clicking the chip opens the agent menu: an agent switcher (multi-agent setups), "What can this agent do?", **Agent settings**, **Settings**, mobile pairing, **Docs**, the build chip, and the color-mode toggle. Rosters above ten agents get a filter field and list pinned agents first; pin or unpin agents from the Agents settings page, with the pinned set stored in the browser profile. Choosing an agent scopes Chat plus Usage, Automations, Tasks, Workboard, and Sessions to that agent. Each scoped page exposes an **Agent** control with **All agents** as an escape; this widens the shared page scope without changing the concrete chat agent, while direct session links still open their target. The Agents settings page keeps its own `?agent=` selection and does not follow the shared page scope. When the gateway runs from a source checkout on a branch other than `main`, the footer also shows that branch name in red so a non-release gateway is obvious at a glance (release installs never show it). Shift-Command-Comma opens **Settings** without overriding the browser's Command-Comma shortcut. The sidebar header also holds the collapse toggle (⌘B); collapsing hides the sidebar entirely for a full-width workspace, and a floating expand control (or ⌘B) brings it back; the macOS app hosts that toggle natively in the titlebar instead. The sidebar is the only navigation chrome on desktop, with no top bar. Narrow viewports swap the sidebar for a slide-over drawer behind a compact header row holding the drawer toggle, brand, and command-palette search; in the macOS app that header row folds the titlebar clearance into a single compact strip beside the window controls. Navigation uses regular browser history, so the browser's back/forward buttons traverse it; the macOS app adds a native sidebar toggle next to the window controls plus trackpad swipe gestures, with back/forward buttons at the sidebar's right edge while it is expanded and native search (command palette) and new-session buttons while it is collapsed.
184+
A **Search** field at the top of the sidebar opens the command palette (⌘K). Clicking the OpenClaw brand in the sidebar header opens the clean New session start screen. When something needs action — failed or overdue cron jobs, expiring or expired model auth — compact attention chips appear above the sidebar footer and click through to the owning page. The footer shows the active agent as a chip — avatar (identity image or emoji), name, connection dot, and a live subtitle — with a **+** for a new session. Clicking the chip opens the agent menu: an agent switcher (multi-agent setups), "What can this agent do?", **Agent settings**, **Settings**, mobile pairing, **Docs**, the build chip, and the color-mode toggle. Rosters above ten agents get a filter field and list pinned agents first; pin or unpin agents from the Agents settings page, with the pinned set stored in the browser profile. Choosing an agent scopes Chat plus Usage, Automations, Tasks, Workboard, and Sessions to that agent. Each scoped page exposes an **Agent** control with **All agents** as an escape; this widens the shared page scope without changing the concrete chat agent, while direct session links still open their target. The Agents settings page keeps its own `?agent=` selection and does not follow the shared page scope. When the gateway runs from a source checkout on a branch other than `main`, the footer also shows that branch name in red so a non-release gateway is obvious at a glance (release installs never show it). Shift-Command-Comma opens **Settings** without overriding the browser's Command-Comma shortcut. The sidebar header also holds the collapse toggle (⌘B); collapsing hides the sidebar entirely for a full-width workspace, and a floating expand control (or ⌘B) brings it back; the macOS app hosts that toggle natively in the titlebar instead. The sidebar is the only navigation chrome on desktop, with no top bar. Narrow viewports swap the sidebar for a slide-over drawer behind a compact header row holding the drawer toggle, brand, and command-palette search; on phones, Chat absorbs that navigation row into its title bar, with the menu and search controls beside the session title. In the macOS app the separate header row folds the titlebar clearance into a single compact strip beside the window controls. Navigation uses regular browser history, so the browser's back/forward buttons traverse it; the macOS app adds a native sidebar toggle next to the window controls plus trackpad swipe gestures, with back/forward buttons at the sidebar's right edge while it is expanded and native search (command palette) and new-session buttons while it is collapsed.
185185

186186
## What it can do (today)
187187

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import { render } from "lit";
44
import { afterEach, describe, expect, it, vi } from "vitest";
55
import type { GatewayBrowserClient } from "../api/gateway.ts";
6+
import {
7+
COMMAND_PALETTE_OPEN_EVENT,
8+
SHELL_NAV_DRAWER_TOGGLE_EVENT,
9+
} from "../components/command-palette-contract.ts";
610
import {
711
BROWSER_PANEL_TOGGLE_EVENT,
812
TERMINAL_PANEL_TOGGLE_EVENT,
@@ -14,6 +18,7 @@ import type {
1418
ApplicationGateway,
1519
ApplicationGatewaySnapshot,
1620
} from "./context.ts";
21+
import { shouldMergeChatChrome } from "./mobile-nav-layout.ts";
1722
import { navigationSurfaceIsHidden, renderFloatingUpdateCard } from "./navigation-surface.ts";
1823

1924
type AppLifecycleState = {
@@ -90,6 +95,15 @@ type ShellNavigationState = {
9095
updated: () => void;
9196
};
9297

98+
type ShellChromeEventState = {
99+
runtime: { context: ApplicationContext };
100+
navDrawerOpen: boolean;
101+
handleShellNavDrawerToggle: (event: Event) => void;
102+
openPalette: () => void;
103+
connectedCallback: () => void;
104+
disconnectedCallback: () => void;
105+
};
106+
93107
type ShellSettingsSearchLoadState = {
94108
runtime: {
95109
context: ApplicationContext;
@@ -107,6 +121,12 @@ type TestWebKitWindow = Window & {
107121

108122
afterEach(() => {
109123
Reflect.deleteProperty(window, "webkit");
124+
document.documentElement.classList.remove(
125+
"openclaw-native-macos",
126+
"openclaw-native-nav",
127+
"openclaw-native-web-chrome",
128+
);
129+
vi.unstubAllGlobals();
110130
});
111131

112132
type ShellEpochState = {
@@ -329,6 +349,68 @@ describe("OpenClaw shell settings search", () => {
329349
});
330350

331351
describe("OpenClaw shell keyboard shortcuts", () => {
352+
it("merges shell chrome only for plain-browser mobile chat", () => {
353+
expect(
354+
shouldMergeChatChrome({ mobileNavLayout: true, routeId: "chat", onboarding: false }),
355+
).toBe(true);
356+
expect(
357+
shouldMergeChatChrome({ mobileNavLayout: false, routeId: "chat", onboarding: false }),
358+
).toBe(false);
359+
expect(
360+
shouldMergeChatChrome({ mobileNavLayout: true, routeId: "sessions", onboarding: false }),
361+
).toBe(false);
362+
expect(
363+
shouldMergeChatChrome({ mobileNavLayout: true, routeId: "chat", onboarding: true }),
364+
).toBe(false);
365+
366+
document.documentElement.classList.add("openclaw-native-nav");
367+
expect(
368+
shouldMergeChatChrome({ mobileNavLayout: true, routeId: "chat", onboarding: false }),
369+
).toBe(false);
370+
});
371+
372+
it("wires merged header window events for the shell lifecycle", () => {
373+
const addEventListener = vi.spyOn(window, "addEventListener");
374+
const shell = document.createElement("openclaw-app-shell") as unknown as ShellChromeEventState;
375+
376+
shell.connectedCallback();
377+
378+
expect(addEventListener).toHaveBeenCalledWith(COMMAND_PALETTE_OPEN_EVENT, expect.any(Function));
379+
expect(addEventListener).toHaveBeenCalledWith(
380+
SHELL_NAV_DRAWER_TOGGLE_EVENT,
381+
expect.any(Function),
382+
);
383+
shell.disconnectedCallback();
384+
addEventListener.mockRestore();
385+
});
386+
387+
it("handles merged header drawer and palette requests", () => {
388+
vi.stubGlobal(
389+
"matchMedia",
390+
vi.fn(() => ({ matches: true })),
391+
);
392+
const openPalette = vi.fn();
393+
const trigger = document.createElement("button");
394+
const shell = document.createElement("openclaw-app-shell") as unknown as ShellChromeEventState;
395+
shell.runtime = {
396+
context: {
397+
navigation: { snapshot: { navCollapsed: false }, update: vi.fn() },
398+
} as unknown as ApplicationContext,
399+
};
400+
Object.defineProperty(shell, "commandPalette", {
401+
configurable: true,
402+
value: { isOpen: false, openPalette, togglePalette: vi.fn() },
403+
});
404+
405+
shell.handleShellNavDrawerToggle(
406+
new CustomEvent(SHELL_NAV_DRAWER_TOGGLE_EVENT, { detail: { trigger } }),
407+
);
408+
shell.openPalette();
409+
410+
expect(shell.navDrawerOpen).toBe(true);
411+
expect(openPalette).toHaveBeenCalledOnce();
412+
});
413+
332414
it("loads and toggles the command palette on its first shortcut", async () => {
333415
const element = createLazyElementSpec("command palette");
334416
const togglePalette = vi.fn();

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ import "../components/update-banner.ts";
2424
import { isSettingsNavigationRoute, type SidebarNavRoute } from "../app-navigation.ts";
2525
import { APP_ROUTE_IDS, isRouteId, type RouteId } from "../app-routes.ts";
2626
import {
27+
COMMAND_PALETTE_OPEN_EVENT,
2728
COMMAND_PALETTE_TARGET_EVENT,
2829
isCommandPaletteShortcut,
30+
SHELL_NAV_DRAWER_TOGGLE_EVENT,
2931
type CommandPaletteElement,
3032
type CommandPaletteTargetDetail,
33+
type ShellNavDrawerToggleDetail,
3134
} from "../components/command-palette-contract.ts";
3235
import { icons } from "../components/icons.ts";
3336
import {
@@ -68,6 +71,7 @@ import {
6871
TERMINAL_PANEL_ELEMENT,
6972
type OptionalCustomElement,
7073
} from "./lazy-custom-element.ts";
74+
import { isMobileNavLayout, shouldMergeChatChrome } from "./mobile-nav-layout.ts";
7175
import { postNativeNavState, type NativeNavState } from "./native-nav-state.ts";
7276
import { considerRouteRestore, persistRoute } from "./native-route-memory.ts";
7377
import {
@@ -186,11 +190,6 @@ function isBrowserPanelAvailable(snapshot: ApplicationContext["gateway"]["snapsh
186190
);
187191
}
188192

189-
function isMobileNavLayout(): boolean {
190-
const maxWidth = isNativeWebChromeHost() ? 600 : 1100;
191-
return globalThis.matchMedia?.(`(max-width: ${maxWidth}px)`).matches ?? false;
192-
}
193-
194193
class OpenClawApp extends OpenClawLightDomElement {
195194
// Pinned while a connect submitted from the visible login gate is in
196195
// flight, so a failed manual attempt cannot flash the shell in between.
@@ -552,6 +551,8 @@ class OpenClawShell extends OpenClawLightDomElement {
552551
super.connectedCallback();
553552
this.nativeHistoryState = readNativeHistoryState();
554553
this.addEventListener(COMMAND_PALETTE_TARGET_EVENT, this.handleCommandPaletteTarget);
554+
window.addEventListener(COMMAND_PALETTE_OPEN_EVENT, this.openPalette);
555+
window.addEventListener(SHELL_NAV_DRAWER_TOGGLE_EVENT, this.handleShellNavDrawerToggle);
555556
document.addEventListener("keydown", this.handleDocumentKeydown);
556557
window.addEventListener("resize", this.handleWindowResize);
557558
window.addEventListener(NATIVE_HISTORY_STATE_EVENT, this.handleNativeHistoryState);
@@ -568,6 +569,8 @@ class OpenClawShell extends OpenClawLightDomElement {
568569

569570
override disconnectedCallback() {
570571
this.removeEventListener(COMMAND_PALETTE_TARGET_EVENT, this.handleCommandPaletteTarget);
572+
window.removeEventListener(COMMAND_PALETTE_OPEN_EVENT, this.openPalette);
573+
window.removeEventListener(SHELL_NAV_DRAWER_TOGGLE_EVENT, this.handleShellNavDrawerToggle);
571574
document.removeEventListener("keydown", this.handleDocumentKeydown);
572575
window.removeEventListener("resize", this.handleWindowResize);
573576
window.removeEventListener(NATIVE_HISTORY_STATE_EVENT, this.handleNativeHistoryState);
@@ -926,6 +929,11 @@ class OpenClawShell extends OpenClawLightDomElement {
926929
this.runWithCommandPalette((palette) => palette.openPalette());
927930
};
928931

932+
private readonly handleShellNavDrawerToggle = (event: Event) => {
933+
const trigger = (event as CustomEvent<ShellNavDrawerToggleDetail>).detail?.trigger;
934+
this.toggleNavigationSurface(trigger instanceof HTMLElement ? trigger : undefined);
935+
};
936+
929937
private readonly togglePalette = () => {
930938
this.runWithCommandPalette((palette) => palette.togglePalette());
931939
};
@@ -1195,6 +1203,11 @@ class OpenClawShell extends OpenClawLightDomElement {
11951203
});
11961204
const navDrawerOpen = this.navDrawerOpen && !this.onboarding;
11971205
const mobileNavLayout = isMobileNavLayout();
1206+
const mergedChatChrome = shouldMergeChatChrome({
1207+
mobileNavLayout,
1208+
routeId: activeRoute,
1209+
onboarding: this.onboarding,
1210+
});
11981211
// Drawer navigation always opens expanded; the desktop collapse preference
11991212
// stays persisted for when the viewport returns to the desktop layout.
12001213
// The settings sidebar has a fixed width, so the collapse state pauses too.
@@ -1226,11 +1239,11 @@ class OpenClawShell extends OpenClawLightDomElement {
12261239
<div
12271240
class="shell ${chatLikeRoute ? "shell--chat" : ""} ${navCollapsed
12281241
? "shell--nav-collapsed"
1229-
: ""} ${mobileNavLayout ? "shell--mobile-nav" : ""} ${navDrawerOpen
1230-
? "shell--nav-drawer-open"
1231-
: ""} ${this.onboarding ? "shell--onboarding" : ""} ${settingsTakeover
1232-
? "shell--settings"
1233-
: ""}"
1242+
: ""} ${mobileNavLayout ? "shell--mobile-nav" : ""} ${mergedChatChrome
1243+
? "shell--merged-chat-chrome"
1244+
: ""} ${navDrawerOpen ? "shell--nav-drawer-open" : ""} ${this.onboarding
1245+
? "shell--onboarding"
1246+
: ""} ${settingsTakeover ? "shell--settings" : ""}"
12341247
style=${`--shell-nav-expanded-width: ${navigationSnapshot.navWidth}px`}
12351248
@keydown=${this.handleShellKeydown}
12361249
@theme-change=${this.handleThemeChange}

‎ui/src/app/mobile-nav-layout.ts‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { RouteId } from "../app-routes.ts";
2+
import { isNativeWebChromeHost } from "./native-web-chrome.ts";
3+
4+
const MOBILE_NAV_MAX_WIDTH = 1100;
5+
const NATIVE_WEB_CHROME_MOBILE_NAV_MAX_WIDTH = 600;
6+
const NATIVE_SHELL_CLASSES = [
7+
"openclaw-native-macos",
8+
"openclaw-native-nav",
9+
"openclaw-native-web-chrome",
10+
] as const;
11+
12+
export function mobileNavLayoutMediaQuery(): string {
13+
const maxWidth = isNativeWebChromeHost()
14+
? NATIVE_WEB_CHROME_MOBILE_NAV_MAX_WIDTH
15+
: MOBILE_NAV_MAX_WIDTH;
16+
return `(max-width: ${maxWidth}px)`;
17+
}
18+
19+
export function isMobileNavLayout(): boolean {
20+
return globalThis.matchMedia?.(mobileNavLayoutMediaQuery()).matches ?? false;
21+
}
22+
23+
function hasNativeShellClass(): boolean {
24+
return NATIVE_SHELL_CLASSES.some((className) =>
25+
document.documentElement.classList.contains(className),
26+
);
27+
}
28+
29+
export function shouldMergeChatChrome(params: {
30+
mobileNavLayout: boolean;
31+
routeId: RouteId;
32+
onboarding: boolean;
33+
}): boolean {
34+
return (
35+
params.mobileNavLayout &&
36+
params.routeId === "chat" &&
37+
!params.onboarding &&
38+
!hasNativeShellClass()
39+
);
40+
}

‎ui/src/components/command-palette-contract.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
export const COMMAND_PALETTE_TARGET_EVENT = "openclaw-command-palette-target";
2+
export const COMMAND_PALETTE_OPEN_EVENT = "openclaw:command-palette-open";
3+
export const SHELL_NAV_DRAWER_TOGGLE_EVENT = "openclaw:shell-nav-drawer-toggle";
4+
5+
export type ShellNavDrawerToggleDetail = {
6+
trigger: HTMLElement;
7+
};
28

39
export function isCommandPaletteShortcut(event: KeyboardEvent): boolean {
410
return (event.metaKey || event.ctrlKey) && !event.shiftKey && event.key.toLowerCase() === "k";

‎ui/src/e2e/native-nav-sidebar-toggle.e2e.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,19 @@ describeControlUiE2e("Control UI native-nav sidebar toggle E2E", () => {
280280
expect(metrics).toEqual({ bodyScrollTop: 0, htmlScrollTop: 0, rootScrollY: 0 });
281281
});
282282

283-
it("keeps the drawer hamburger at narrow widths in plain browsers", async () => {
283+
it("moves drawer and search controls into the narrow chat title bar", async () => {
284284
const page = await openPage({ nativeNav: false, width: 900 });
285-
await expect.poll(() => page.locator(".topbar-nav-toggle").isVisible()).toBe(true);
285+
const header = page.locator(".chat-pane__header").first();
286+
await expect
287+
.poll(() => page.locator(".shell").getAttribute("class"))
288+
.toContain("shell--merged-chat-chrome");
289+
await expect.poll(() => page.locator(".topbar").isVisible()).toBe(false);
290+
await expect
291+
.poll(() => header.getByRole("button", { name: "Expand sidebar" }).isVisible())
292+
.toBe(true);
293+
await expect
294+
.poll(() => header.getByRole("button", { name: "Open command palette" }).isVisible())
295+
.toBe(true);
286296
});
287297

288298
it("keeps the sidebar rail beside a half-width native link browser", async () => {

‎ui/src/pages/chat/chat-page.test.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type RenderedPane = HTMLElement & {
2525
active: boolean;
2626
paneTitle: string;
2727
narrow: boolean;
28+
mergedChrome: boolean;
2829
onOpenSplitView?: () => void;
2930
onClosePane?: (paneId: string) => void;
3031
};
@@ -103,9 +104,9 @@ function setNavigationContext(page: ChatPage) {
103104
function stubMatchMedia(matches: boolean) {
104105
vi.stubGlobal(
105106
"matchMedia",
106-
vi.fn(() => ({
107+
vi.fn((query: string) => ({
107108
matches,
108-
media: "(max-width: 1099px)",
109+
media: query,
109110
onchange: null,
110111
addEventListener: vi.fn(),
111112
removeEventListener: vi.fn(),
@@ -141,6 +142,7 @@ describe("chat page split layout host", () => {
141142
expect(itemAt(panes, 0, "rendered pane").paneId).toBe("p1");
142143
expect(itemAt(panes, 0, "rendered pane").sessionKey).toBe("main");
143144
expect(itemAt(panes, 0, "rendered pane").active).toBe(true);
145+
expect(itemAt(panes, 0, "rendered pane").mergedChrome).toBe(false);
144146
expect(itemAt(panes, 0, "rendered pane").classList.contains("chat-split-view__pane")).toBe(
145147
false,
146148
);
@@ -149,6 +151,19 @@ describe("chat page split layout host", () => {
149151
expect(typeof itemAt(panes, 0, "rendered pane").onOpenSplitView).toBe("function");
150152
});
151153

154+
it("passes merged chrome from the shared mobile-nav query", async () => {
155+
stubMatchMedia(true);
156+
const page = new ChatPage();
157+
page.data = { sessionKey: "main" };
158+
document.body.append(page);
159+
await page.updateComplete;
160+
161+
const pane = itemAt(page.querySelectorAll<RenderedPane>("openclaw-chat-pane"), 0, "pane");
162+
expect(pane.mergedChrome).toBe(true);
163+
expect(matchMedia).toHaveBeenCalledWith("(max-width: 1099px)");
164+
expect(matchMedia).toHaveBeenCalledWith("(max-width: 1100px)");
165+
});
166+
152167
it("retains the classic pane element while split view opens and closes", async () => {
153168
const page = new ChatPage();
154169
page.data = { sessionKey: "main" };

0 commit comments

Comments
 (0)