Skip to content

Commit 4788f76

Browse files
improve(ui): refine chat image presentation and controls (#131811)
* improve(ui): refine chat image presentation and controls * fix(ui): address chat image review findings * style(ui): format chat image coverage
1 parent c1c1c8d commit 4788f76

10 files changed

Lines changed: 452 additions & 70 deletions

‎ui/src/components/image-lightbox.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,16 @@ class OpenClawImageLightbox extends OpenClawLitElement {
5252

5353
static override styles = css`
5454
:host {
55+
--image-lightbox-control-background: rgba(12, 16, 24, 0.64);
56+
--image-lightbox-control-background-hover: rgba(12, 16, 24, 0.78);
5557
display: contents;
5658
}
5759
60+
:host-context([data-theme-mode="dark"]) {
61+
--image-lightbox-control-background: rgba(255, 255, 255, 0.16);
62+
--image-lightbox-control-background-hover: rgba(255, 255, 255, 0.22);
63+
}
64+
5865
openclaw-modal-dialog {
5966
--openclaw-modal-width: 100vw;
6067
--openclaw-modal-max-width: 100vw;
@@ -84,16 +91,23 @@ class OpenClawImageLightbox extends OpenClawLitElement {
8491
gap: 4px;
8592
}
8693
94+
.actions .action,
95+
.action.zoom-control {
96+
color: var(--media-foreground);
97+
background-color: var(--image-lightbox-control-background);
98+
-webkit-backdrop-filter: blur(16px) saturate(140%);
99+
backdrop-filter: blur(16px) saturate(140%);
100+
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.18);
101+
}
102+
87103
.actions .action {
88104
border-radius: 999px;
89-
background-color: color-mix(in srgb, var(--text) 10%, transparent);
90-
-webkit-backdrop-filter: blur(12px);
91-
backdrop-filter: blur(12px);
92105
transition: background-color 180ms ease;
93106
}
94107
95-
.actions .action:hover {
96-
background-color: color-mix(in srgb, var(--text) 16%, transparent);
108+
.actions .action:hover,
109+
.zoom-control:hover:not(:disabled) {
110+
background-color: var(--image-lightbox-control-background-hover);
97111
}
98112
99113
.title {
@@ -201,14 +215,11 @@ class OpenClawImageLightbox extends OpenClawLitElement {
201215
min-height: 40px;
202216
padding: 0 10px;
203217
border: 0;
204-
background: color-mix(in srgb, var(--text) 10%, transparent);
205-
-webkit-backdrop-filter: blur(12px);
206-
backdrop-filter: blur(12px);
207218
font-size: 15px;
208219
}
209220
210221
.zoom-control:disabled {
211-
color: rgba(255, 255, 255, 0.35);
222+
color: rgba(255, 255, 255, 0.8);
212223
}
213224
214225
.zoom-level {

‎ui/src/e2e/chat-image-lightbox.e2e.test.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,49 @@ describeControlUiE2e("Control UI image lightbox", () => {
130130
const openOriginal = page.getByRole("link", { name: "Open in new tab" });
131131
await openOriginal.waitFor({ state: "visible" });
132132
await expect.poll(() => openOriginal.getAttribute("href")).toMatch(/^blob:/);
133+
const readControlContrast = () =>
134+
page.locator("openclaw-image-lightbox").evaluate((lightbox) => {
135+
const root = lightbox.shadowRoot!;
136+
return [".open-original", ".close", '[aria-label="Zoom in"]'].map((selector) => {
137+
const style = getComputedStyle(root.querySelector(selector)!);
138+
return {
139+
backdropFilter: style.backdropFilter,
140+
backgroundColor: style.backgroundColor,
141+
borderWidth: style.borderWidth,
142+
color: style.color,
143+
};
144+
});
145+
});
146+
for (const [theme, backgroundColor] of [
147+
["dark", "rgba(255, 255, 255, 0.16)"],
148+
["light", "rgba(12, 16, 24, 0.64)"],
149+
] as const) {
150+
await page.evaluate(
151+
(mode) => document.documentElement.setAttribute("data-theme-mode", mode),
152+
theme,
153+
);
154+
await expect.poll(readControlContrast).toEqual([
155+
expect.objectContaining({
156+
backdropFilter: expect.stringContaining("blur(16px)"),
157+
backgroundColor,
158+
borderWidth: "0px",
159+
color: "rgb(255, 255, 255)",
160+
}),
161+
expect.objectContaining({
162+
backdropFilter: expect.stringContaining("blur(16px)"),
163+
backgroundColor,
164+
borderWidth: "0px",
165+
color: "rgb(255, 255, 255)",
166+
}),
167+
expect.objectContaining({
168+
backdropFilter: expect.stringContaining("blur(16px)"),
169+
backgroundColor,
170+
borderWidth: "0px",
171+
color: "rgb(255, 255, 255)",
172+
}),
173+
]);
174+
}
175+
await page.evaluate(() => document.documentElement.setAttribute("data-theme-mode", "dark"));
133176
const focusIsInsideLightbox = () =>
134177
page.locator("openclaw-image-lightbox").evaluate((lightbox) => {
135178
let active: Element | null = document.activeElement;

‎ui/src/e2e/managed-image-actions.e2e.test.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ suite.define(() => {
9494
const imageFrame = page.locator(".chat-image-frame--managed").filter({ has: image });
9595
await imageFrame.hover();
9696
const imageActions = imageFrame.locator(".chat-image-actions");
97+
await expect.poll(() => imageActions.getByRole("button").count()).toBe(2);
98+
await expect
99+
.poll(() =>
100+
imageActions.getByRole("button", { name: "Open image Ticketed generated image" }).count(),
101+
)
102+
.toBe(0);
97103
const downloadButton = imageActions.getByRole("button", { name: "Download image" });
98104
await expect
99105
.poll(() =>
@@ -118,9 +124,7 @@ suite.define(() => {
118124
await downloadButton.click();
119125
expect((await download).suggestedFilename()).toBe("Ticketed generated image.png");
120126

121-
await imageActions
122-
.getByRole("button", { name: "Open image Ticketed generated image" })
123-
.click();
127+
await page.getByRole("button", { name: "Open image Ticketed generated image" }).click();
124128
await page
125129
.getByRole("dialog", { name: "Image preview: Ticketed generated image" })
126130
.waitFor({ state: "visible" });

‎ui/src/pages/chat/chat-responsive.browser.test.ts‎

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,190 @@ describeBrowserLayout.concurrent("chat responsive browser layout", () => {
22412241
}
22422242
});
22432243

2244+
it("keeps managed image actions anchored around tiny rendered images", async () => {
2245+
const page = await openBrowserPage(1280, 900);
2246+
try {
2247+
await page.setContent(
2248+
`<!doctype html><html><head><style>${readUiCss()}</style></head><body>
2249+
<div class="chat-message-images">
2250+
<span class="chat-image-frame chat-image-frame--managed">
2251+
<button class="chat-message-image-button" type="button">
2252+
<img
2253+
class="chat-message-image chat-message-image--small"
2254+
width="16"
2255+
height="16"
2256+
alt="Tiny generated image"
2257+
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16'%3E%3Crect width='16' height='16' fill='%23dc4f92'/%3E%3C/svg%3E"
2258+
/>
2259+
</button>
2260+
<span class="chat-image-actions">
2261+
<button class="chat-image-action" type="button">1</button>
2262+
<button class="chat-image-action" type="button">2</button>
2263+
</span>
2264+
</span>
2265+
<span class="chat-image-frame chat-image-frame--managed">
2266+
<button class="chat-message-image-button" type="button">
2267+
<img
2268+
class="chat-message-image"
2269+
width="420"
2270+
height="1800"
2271+
alt="Tall generated image"
2272+
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='1800'%3E%3Crect width='420' height='1800' fill='%235c86ff'/%3E%3C/svg%3E"
2273+
/>
2274+
</button>
2275+
<span class="chat-image-actions">
2276+
<button class="chat-image-action" type="button">1</button>
2277+
<button class="chat-image-action" type="button">2</button>
2278+
</span>
2279+
</span>
2280+
</div>
2281+
</body></html>`,
2282+
);
2283+
const frames = page.locator(".chat-image-frame--managed");
2284+
await expect.poll(() => frames.count()).toBe(2);
2285+
const frameRows = await frames.evaluateAll((elements) =>
2286+
elements.map((element) => {
2287+
const box = element.getBoundingClientRect();
2288+
return { bottom: box.bottom, top: box.top };
2289+
}),
2290+
);
2291+
expect(frameRows[1]!.top).toBeGreaterThan(frameRows[0]!.bottom);
2292+
for (const [index, expectedWidth] of [160, 84].entries()) {
2293+
const frame = frames.nth(index);
2294+
await frame.hover();
2295+
await expect
2296+
.poll(() => frame.evaluate((element) => getComputedStyle(element, "::after").opacity))
2297+
.toBe("1");
2298+
const geometry = await frame.evaluate((element) => {
2299+
const actions = element.querySelector<HTMLElement>(".chat-image-actions")!;
2300+
const frameRect = element.getBoundingClientRect();
2301+
const actionsRect = actions.getBoundingClientRect();
2302+
return {
2303+
actionsInsideFrame:
2304+
actionsRect.left >= frameRect.left &&
2305+
actionsRect.right <= frameRect.right &&
2306+
actionsRect.top >= frameRect.top &&
2307+
actionsRect.bottom <= frameRect.bottom,
2308+
actionsNearBottom: frameRect.bottom - actionsRect.bottom <= 9,
2309+
fadeWidth: Number.parseFloat(getComputedStyle(element, "::after").width),
2310+
frameWidth: frameRect.width,
2311+
overflow: getComputedStyle(element).overflow,
2312+
};
2313+
});
2314+
expect(geometry.actionsInsideFrame).toBe(true);
2315+
expect(geometry.actionsNearBottom).toBe(true);
2316+
expect(geometry.fadeWidth).toBeCloseTo(geometry.frameWidth, 0);
2317+
expect(geometry.frameWidth).toBeCloseTo(expectedWidth, 0);
2318+
expect(geometry.overflow).toBe("hidden");
2319+
}
2320+
} finally {
2321+
await closeBrowserPage(page);
2322+
}
2323+
});
2324+
2325+
it("places a five-image sent gallery above its separate text bubble", async () => {
2326+
const page = await openBrowserPage(1280, 900);
2327+
try {
2328+
const tile = (index: number) => `
2329+
<span class="chat-image-frame" data-tile="${index}">
2330+
<button class="chat-message-image-button" type="button">
2331+
<img class="chat-message-image" width="640" height="640" alt="Image ${index}"
2332+
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='640' height='640'%3E%3Crect width='640' height='640' fill='%23865cff'/%3E%3C/svg%3E" />
2333+
</button>
2334+
</span>`;
2335+
await page.setContent(
2336+
`<!doctype html><html><head><style>${readUiCss()}</style></head><body>
2337+
<div class="chat-group user">
2338+
<div class="chat-bubble chat-bubble--with-images">
2339+
<div
2340+
class="chat-message-images chat-message-images--gallery chat-message-images--five"
2341+
>
2342+
${Array.from({ length: 5 }, (_, index) => tile(index + 1)).join("")}
2343+
</div>
2344+
<div class="chat-text">oi</div>
2345+
</div>
2346+
</div>
2347+
</body></html>`,
2348+
);
2349+
await page.locator(".chat-message-image").first().waitFor();
2350+
const geometry = await page.locator(".chat-bubble").evaluate((bubble) => {
2351+
const gallery = bubble.querySelector<HTMLElement>(".chat-message-images")!;
2352+
const text = bubble.querySelector<HTMLElement>(".chat-text")!;
2353+
const frames = [...gallery.querySelectorAll<HTMLElement>(".chat-image-frame")];
2354+
const boxes = frames.map((frame) => frame.getBoundingClientRect());
2355+
const galleryBox = gallery.getBoundingClientRect();
2356+
const textBox = text.getBoundingClientRect();
2357+
return {
2358+
background: getComputedStyle(bubble).backgroundColor,
2359+
firstRow: boxes.filter((box) => Math.round(box.top) === Math.round(boxes[0]!.top)).length,
2360+
fourthAlignedWithSecond: Math.abs(boxes[3]!.left - boxes[1]!.left) <= 1,
2361+
lastRowRightAligned: Math.abs(boxes[4]!.right - galleryBox.right) <= 1,
2362+
textBelow: textBox.top >= galleryBox.bottom + 7,
2363+
textRightAligned: Math.abs(textBox.right - galleryBox.right) <= 1,
2364+
tileSize: boxes[0]!.width,
2365+
};
2366+
});
2367+
expect(geometry).toMatchObject({
2368+
background: "rgba(0, 0, 0, 0)",
2369+
firstRow: 3,
2370+
fourthAlignedWithSecond: true,
2371+
lastRowRightAligned: true,
2372+
textBelow: true,
2373+
textRightAligned: true,
2374+
});
2375+
expect(geometry.tileSize).toBeCloseTo(128, 0);
2376+
} finally {
2377+
await closeBrowserPage(page);
2378+
}
2379+
});
2380+
2381+
it("keeps every sent-image text shape on the user bubble surface", async () => {
2382+
const page = await openBrowserPage(1280, 900);
2383+
try {
2384+
await page.setContent(
2385+
`<!doctype html><html><head><style>${readUiCss()}</style></head><body>
2386+
<div class="chat-group user">
2387+
<div class="chat-bubble chat-bubble--with-images">
2388+
<div class="chat-text" data-shape="text">Short text</div>
2389+
</div>
2390+
<div class="chat-bubble chat-bubble--with-images">
2391+
<div class="chat-message-disclosure" data-shape="disclosure">
2392+
<div class="chat-message-disclosure__content">
2393+
<div class="chat-text">Collapsed text</div>
2394+
</div>
2395+
</div>
2396+
</div>
2397+
<div class="chat-bubble chat-bubble--with-images">
2398+
<details class="chat-json-collapse" data-shape="json">
2399+
<summary class="chat-json-summary">JSON</summary>
2400+
</details>
2401+
</div>
2402+
</div>
2403+
</body></html>`,
2404+
);
2405+
for (const theme of ["dark", "light"] as const) {
2406+
await page.evaluate(
2407+
(mode) => document.documentElement.setAttribute("data-theme-mode", mode),
2408+
theme,
2409+
);
2410+
const surfaces = await page.locator("[data-shape]").evaluateAll((elements) =>
2411+
elements.map((element) => {
2412+
const style = getComputedStyle(element);
2413+
return {
2414+
backgroundColor: style.backgroundColor,
2415+
padding: style.padding,
2416+
};
2417+
}),
2418+
);
2419+
expect(surfaces[0]).toMatchObject({ padding: "10px 14px" });
2420+
expect(surfaces[1]).toEqual(surfaces[0]);
2421+
expect(surfaces[2]).toEqual(surfaces[0]);
2422+
}
2423+
} finally {
2424+
await closeBrowserPage(page);
2425+
}
2426+
});
2427+
22442428
it("wraps long question and approval metadata inside narrow cards", async () => {
22452429
const page = await openBrowserPage(320, 568);
22462430
try {

‎ui/src/pages/chat/components/chat-message-bubble.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export function renderGroupedMessage(
320320

321321
const bubbleClasses = [
322322
"chat-bubble",
323+
hasImages ? "chat-bubble--with-images" : "",
323324
isToolShell ? "chat-bubble--tool-shell" : "",
324325
opts.isStreaming ? "streaming" : "",
325326
opts.entryAnimated ? "chat-bubble--user-turn-enter" : "",

0 commit comments

Comments
 (0)