Skip to content

Commit e052d12

Browse files
authored
fix(ui): make scrollbars contextual (#107349)
1 parent ee47235 commit e052d12

5 files changed

Lines changed: 264 additions & 11 deletions

File tree

‎ui/src/components/form-controls.browser.test.ts‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,77 @@ describeBrowserLayout("mount fallback cursor", () => {
220220
}
221221
});
222222
});
223+
224+
describeBrowserLayout("app chrome interaction styles", () => {
225+
it("keeps sidebars compact while preserving normal content scroll and text entry", async () => {
226+
const browser = await chromium.launch({
227+
executablePath: chromiumExecutablePath,
228+
headless: true,
229+
});
230+
try {
231+
const page = await browser.newPage({ viewport: { width: 1200, height: 800 } });
232+
await page.setContent(`
233+
<!doctype html>
234+
<html>
235+
<head><style>${readUiCss()}</style></head>
236+
<body>
237+
<aside class="settings-sidebar">
238+
<nav class="settings-sidebar__nav">
239+
<span class="settings-sidebar__item-label">Settings row</span>
240+
</nav>
241+
<input class="settings-sidebar__search-input" value="editable settings search" />
242+
</aside>
243+
<aside class="sidebar">
244+
<div class="sidebar-recent-sessions">Recent session</div>
245+
</aside>
246+
<main class="content" style="height: 100px">
247+
<div class="settings-card">App chrome tile</div>
248+
<div style="height: 200px"></div>
249+
</main>
250+
<section class="chat-thread" style="height: 100px">Selectable transcript</section>
251+
</body>
252+
</html>
253+
`);
254+
255+
const metrics = await page.evaluate(() => {
256+
const style = (selector: string) => {
257+
const node = document.querySelector(selector);
258+
if (!(node instanceof HTMLElement)) {
259+
throw new Error(`Missing interaction fixture ${selector}`);
260+
}
261+
return getComputedStyle(node);
262+
};
263+
const scrollbarWidth = (selector: string) => {
264+
const node = document.querySelector(selector);
265+
if (!(node instanceof HTMLElement)) {
266+
throw new Error(`Missing scrollbar fixture ${selector}`);
267+
}
268+
return getComputedStyle(node, "::-webkit-scrollbar").width;
269+
};
270+
return {
271+
chatSelection: style(".chat-thread").userSelect,
272+
chromeSelection: style(".settings-card").userSelect,
273+
contentScrollbar: scrollbarWidth(".content"),
274+
inputSelection: style(".settings-sidebar__search-input").userSelect,
275+
regularSidebarScrollbar: scrollbarWidth(".sidebar-recent-sessions"),
276+
regularSidebarSelection: style(".sidebar-recent-sessions").userSelect,
277+
settingsSidebarScrollbar: scrollbarWidth(".settings-sidebar__nav"),
278+
settingsSidebarSelection: style(".settings-sidebar__nav").userSelect,
279+
};
280+
});
281+
282+
expect(metrics).toEqual({
283+
chatSelection: "text",
284+
chromeSelection: "none",
285+
contentScrollbar: "12px",
286+
inputSelection: "text",
287+
regularSidebarScrollbar: "6px",
288+
regularSidebarSelection: "none",
289+
settingsSidebarScrollbar: "6px",
290+
settingsSidebarSelection: "none",
291+
});
292+
} finally {
293+
await browser.close().catch(() => {});
294+
}
295+
});
296+
});
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
// Control UI tests cover contextual scrollbars and native-style text selection.
2+
import { mkdir } from "node:fs/promises";
3+
import path from "node:path";
4+
import { chromium, type Browser, type Locator, type Page } from "playwright";
5+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
6+
import {
7+
canRunPlaywrightChromium,
8+
installMockGateway,
9+
resolvePlaywrightChromiumExecutablePath,
10+
startControlUiE2eServer,
11+
type ControlUiE2eServer,
12+
} from "../test-helpers/control-ui-e2e.ts";
13+
14+
const chromiumExecutablePath = resolvePlaywrightChromiumExecutablePath(chromium.executablePath());
15+
const chromiumAvailable = canRunPlaywrightChromium(chromiumExecutablePath);
16+
const allowMissingChromium = process.env.OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM === "1";
17+
const describeControlUiE2e = chromiumAvailable || !allowMissingChromium ? describe : describe.skip;
18+
const captureUiProofEnabled = process.env.OPENCLAW_CAPTURE_UI_PROOF === "1";
19+
const uiProofArtifactDir = path.join(
20+
process.cwd(),
21+
".artifacts",
22+
"control-ui-e2e",
23+
"app-chrome-interaction",
24+
);
25+
26+
let browser: Browser;
27+
let server: ControlUiE2eServer;
28+
29+
async function dragAcross(page: Page, locator: Locator): Promise<string> {
30+
await locator.scrollIntoViewIfNeeded();
31+
const box = await locator.boundingBox();
32+
if (!box) {
33+
throw new Error("Expected a visible text-selection target");
34+
}
35+
const y = box.y + box.height / 2;
36+
await page.mouse.move(box.x + 2, y);
37+
await page.mouse.down();
38+
await page.mouse.move(box.x + Math.max(3, box.width - 2), y, { steps: 8 });
39+
await page.mouse.up();
40+
return page.evaluate(() => globalThis.getSelection()?.toString() ?? "");
41+
}
42+
43+
async function captureUiProof(page: Page, fileName: string) {
44+
if (!captureUiProofEnabled) {
45+
return;
46+
}
47+
await mkdir(uiProofArtifactDir, { recursive: true });
48+
await page.screenshot({
49+
animations: "disabled",
50+
path: path.join(uiProofArtifactDir, fileName),
51+
});
52+
}
53+
54+
describeControlUiE2e("Control UI app chrome interaction mocked Gateway E2E", () => {
55+
beforeAll(async () => {
56+
if (!chromiumAvailable) {
57+
throw new Error(
58+
`Playwright Chromium is not installed or cannot start at ${chromiumExecutablePath}. Run \`pnpm --dir ui exec playwright install --with-deps chromium\`, or set OPENCLAW_UI_E2E_ALLOW_MISSING_CHROMIUM=1 only when intentionally skipping this lane.`,
59+
);
60+
}
61+
server = await startControlUiE2eServer();
62+
browser = await chromium.launch({ executablePath: chromiumExecutablePath });
63+
});
64+
65+
afterAll(async () => {
66+
await browser?.close();
67+
await server?.close();
68+
});
69+
70+
it("uses compact sidebar scrollbars and keeps selection in chat and inputs", async () => {
71+
if (captureUiProofEnabled) {
72+
await mkdir(uiProofArtifactDir, { recursive: true });
73+
}
74+
const context = await browser.newContext({
75+
locale: "en-US",
76+
recordVideo: captureUiProofEnabled
77+
? { dir: path.join(uiProofArtifactDir, "video"), size: { height: 900, width: 1440 } }
78+
: undefined,
79+
serviceWorkers: "block",
80+
viewport: { height: 900, width: 1440 },
81+
});
82+
const page = await context.newPage();
83+
await installMockGateway(page, {
84+
historyMessages: [
85+
{
86+
role: "assistant",
87+
content: [{ type: "text", text: "Selectable transcript content" }],
88+
},
89+
],
90+
});
91+
92+
try {
93+
await page.goto(`${server.baseUrl}chat`);
94+
const transcript = page.getByText("Selectable transcript content", { exact: true });
95+
await transcript.waitFor();
96+
const chatStyles = await page.evaluate(() => {
97+
const sidebar = document.querySelector<HTMLElement>(".sidebar");
98+
const sessions = document.querySelector<HTMLElement>(".sidebar-recent-sessions");
99+
const thread = document.querySelector<HTMLElement>(".chat-thread");
100+
if (!sidebar || !sessions || !thread) {
101+
throw new Error("Missing chat interaction surface");
102+
}
103+
return {
104+
chatSelection: getComputedStyle(thread).userSelect,
105+
chatScrollbar: getComputedStyle(thread, "::-webkit-scrollbar").width,
106+
sidebarSelection: getComputedStyle(sidebar).userSelect,
107+
sidebarScrollbar: getComputedStyle(sessions, "::-webkit-scrollbar").width,
108+
};
109+
});
110+
expect(chatStyles).toEqual({
111+
chatSelection: "text",
112+
chatScrollbar: "12px",
113+
sidebarSelection: "none",
114+
sidebarScrollbar: "6px",
115+
});
116+
expect(await dragAcross(page, transcript)).toContain("Selectable transcript");
117+
await captureUiProof(page, "01-chat-selectable-transcript.png");
118+
119+
await page.goto(`${server.baseUrl}settings/general`);
120+
const settingsSidebar = page.locator(".settings-sidebar");
121+
const settingsTitle = settingsSidebar.locator(".settings-sidebar__title");
122+
const settingsSearch = settingsSidebar.locator(".settings-sidebar__search-input");
123+
const content = page.locator(".content");
124+
await settingsSidebar.waitFor();
125+
await expect
126+
.poll(() => content.evaluate((element) => element.scrollHeight))
127+
.toBeGreaterThan(await content.evaluate((element) => element.clientHeight));
128+
129+
const settingsStyles = await page.evaluate(() => {
130+
const contentNode = document.querySelector<HTMLElement>(".content");
131+
const nav = document.querySelector<HTMLElement>(".settings-sidebar__nav");
132+
const search = document.querySelector<HTMLElement>(".settings-sidebar__search-input");
133+
const sidebar = document.querySelector<HTMLElement>(".settings-sidebar");
134+
if (!contentNode || !nav || !search || !sidebar) {
135+
throw new Error("Missing settings interaction surface");
136+
}
137+
return {
138+
contentScrollbar: getComputedStyle(contentNode, "::-webkit-scrollbar").width,
139+
contentSelection: getComputedStyle(contentNode).userSelect,
140+
inputSelection: getComputedStyle(search).userSelect,
141+
sidebarScrollbar: getComputedStyle(nav, "::-webkit-scrollbar").width,
142+
sidebarSelection: getComputedStyle(sidebar).userSelect,
143+
};
144+
});
145+
expect(settingsStyles).toEqual({
146+
contentScrollbar: "12px",
147+
contentSelection: "none",
148+
inputSelection: "text",
149+
sidebarScrollbar: "6px",
150+
sidebarSelection: "none",
151+
});
152+
153+
await page.evaluate(() => globalThis.getSelection()?.removeAllRanges());
154+
expect(await dragAcross(page, settingsTitle)).toBe("");
155+
await settingsSearch.selectText();
156+
expect(
157+
await settingsSearch.evaluate(
158+
(element) =>
159+
element instanceof HTMLInputElement &&
160+
element.selectionStart === 0 &&
161+
element.selectionEnd === element.value.length,
162+
),
163+
).toBe(true);
164+
await content.evaluate((element) => {
165+
element.scrollTop = Math.min(160, element.scrollHeight - element.clientHeight);
166+
});
167+
await captureUiProof(page, "02-settings-contextual-scrollbars.png");
168+
} finally {
169+
await context.close();
170+
}
171+
});
172+
});

‎ui/src/styles/base.css‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ body {
529529
letter-spacing: -0.01em;
530530
background: var(--bg);
531531
color: var(--text);
532+
/* App chrome behaves like native controls: dragging across labels, tiles,
533+
and navigation must not create accidental text selections. Text-entry
534+
surfaces and document-like content opt back in below or in route CSS. */
535+
user-select: none;
532536
-webkit-font-smoothing: antialiased;
533537
-moz-osx-font-smoothing: grayscale;
534538
}
@@ -619,15 +623,22 @@ select {
619623
color: inherit;
620624
}
621625

626+
input,
627+
textarea,
628+
[contenteditable]:not([contenteditable="false"]) {
629+
user-select: text;
630+
}
631+
622632
::selection {
623633
background: var(--selection-bg);
624634
color: var(--selection-fg);
625635
}
626636

627-
/* Scrollbar styling - Minimal, barely visible */
637+
/* Main/document surfaces keep a normal scrollbar hit target. Dense sidebars
638+
override this inherited size locally so their row actions retain room. */
628639
::-webkit-scrollbar {
629-
width: 6px;
630-
height: 6px;
640+
width: var(--scrollbar-size, 12px);
641+
height: var(--scrollbar-size, 12px);
631642
}
632643

633644
::-webkit-scrollbar-track {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ openclaw-chat-page {
109109
/* Grow, shrink, and use 0 base for proper scrolling */
110110
overflow-y: auto;
111111
overflow-x: hidden;
112+
/* The transcript is document content, unlike the surrounding app chrome. */
113+
user-select: text;
112114
scrollbar-gutter: stable both-edges;
113115
scrollbar-color: var(--muted-strong) transparent;
114116
/* The tall top inset is a titlebar band: it keeps the floating rail

‎ui/src/styles/layout.css‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ html.openclaw-native-web-chrome .sidebar-brand__collapse {
238238
}
239239

240240
.settings-sidebar {
241+
--scrollbar-size: 6px;
241242
display: flex;
242243
flex-direction: column;
243244
flex: 1;
@@ -795,6 +796,7 @@ html.openclaw-native-web-chrome .sidebar-brand__collapse {
795796
/* Sticky headers inside the sidebar reuse --sidebar-bg so scrolled rows
796797
never shine through with a mismatched tone. */
797798
--sidebar-bg: color-mix(in srgb, var(--bg) 96%, var(--bg-elevated) 4%);
799+
--scrollbar-size: 6px;
798800
position: relative;
799801
display: flex;
800802
flex-direction: column;
@@ -803,14 +805,6 @@ html.openclaw-native-web-chrome .sidebar-brand__collapse {
803805
min-width: 0;
804806
overflow: hidden;
805807
background: var(--sidebar-bg);
806-
/* Sidebar chrome is controls, not copy; drag-selecting row labels reads as
807-
broken. Editable fields inside (menu filters) re-enable selection below. */
808-
user-select: none;
809-
}
810-
811-
.sidebar input,
812-
.sidebar textarea {
813-
user-select: text;
814808
}
815809

816810
:root[data-theme-mode="light"] .sidebar {

0 commit comments

Comments
 (0)