Skip to content

Commit 8187d3c

Browse files
zoomote[bot]roomote
andauthored
[Fix] Chat and History labels clip at narrow widths (#1445)
* fix(visual): detect clipped responsive text * fix(visual): preserve compact label breakpoint * fix(chat): scope reflow above sidebar baseline --------- Co-authored-by: Roomote <[email protected]>
1 parent 8f7f48a commit 8187d3c

9 files changed

Lines changed: 136 additions & 76 deletions

File tree

‎.github/pull_request_template.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Detail the steps to test your changes. This helps reviewers verify your work.
4646

4747
<!--
4848
For UI changes to static rendered state, the primary artifact is a committed
49-
Playwright CT snapshot (`*.visual.tsx` in `webview-ui/`) — that baseline
49+
Playwright Story Gallery snapshot (`*.visual.tsx` in `webview-ui/`) — that baseline
5050
becomes durable regression coverage for the surface. See
5151
`webview-ui/AGENTS.md` for what deserves a snapshot.
5252

‎.github/workflows/visual-regression.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Webview Visual Regression
1+
name: Visual Regression
22

33
on:
44
workflow_dispatch:

‎apps/vscode-e2e/AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The Playwright Electron suite under `src/visual/` is a small production-parity l
1515
- Identify the Zoo Code webview by its extension ID and frame ancestry, not generated frame IDs or names.
1616
- Keep window geometry, theme, locale, fonts, provider responses, pointer position, and focus deterministic.
1717
- Commit only baselines generated by the pinned CI/Xvfb runner. Failure artifacts include the Playwright report and expected/actual/diff images.
18+
- To recover an intentional Electron baseline change, download the failed run's `extension-host-visual-regression` artifact, inspect the relevant `*-actual.png`, copy it to `src/visual/__screenshots__` without the `-actual` suffix, then push and require the repeated job to pass.
1819
- Treat `_electron` compatibility as part of each pinned VS Code/Playwright upgrade because the API is experimental and depends on Electron fuse support.
1920

2021
## How aimock matching works

‎apps/vscode-e2e/src/visual/electron.visual.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,8 @@ async function startScene(
183183
await app?.close().catch(() => undefined)
184184
await mock?.stop().catch(() => undefined)
185185
await fs.rm(temporaryRoot, { recursive: true, force: true })
186-
const message = error instanceof Error ? error.message : String(error)
187-
throw new Error(message)
186+
if (error instanceof Error) throw error
187+
throw new Error(String(error))
188188
}
189189
}
190190

‎webview-ui/playwright/gallery/stories.tsx‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ export const stories: Record<string, Story> = {
5050
</AppProviders>
5151
)
5252
},
53+
"layout-clipped-text": () => (
54+
<div className="w-40">
55+
<span data-testid="clipped-direct-text" className="block w-8 overflow-hidden whitespace-nowrap">
56+
Clipped direct text
57+
</span>
58+
</div>
59+
),
60+
"layout-screen-reader-only": () => (
61+
<div>
62+
<label className="sr-only">Hidden label</label>
63+
<div className="sr-only">
64+
<button>Hidden action</button>
65+
</div>
66+
</div>
67+
),
5368
"mermaid-gantt": async () => {
5469
const { default: MermaidBlock } = await import("@/components/common/MermaidBlock")
5570
return <MermaidBlock code={mermaidGantt} />

‎webview-ui/playwright/layout-contracts.ts‎

Lines changed: 93 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,98 @@ interface BoundedLayoutOptions {
1414
focusedControl: Locator
1515
}
1616

17+
export function collectBoundedLayoutFailures(element: HTMLElement) {
18+
const tolerance = 1
19+
const viewportWidth = document.documentElement.clientWidth
20+
const isScreenReaderOnly = (candidate: HTMLElement) => {
21+
let current: HTMLElement | null = candidate
22+
while (current && element.contains(current)) {
23+
const styles = getComputedStyle(current)
24+
if (
25+
current.classList.contains("sr-only") ||
26+
(styles.position === "absolute" &&
27+
current.offsetWidth <= 1 &&
28+
current.offsetHeight <= 1 &&
29+
(styles.clip !== "auto" || styles.clipPath !== "none"))
30+
) {
31+
return true
32+
}
33+
current = current.parentElement
34+
}
35+
return false
36+
}
37+
const semanticCandidates = Array.from(
38+
element.querySelectorAll<HTMLElement>(
39+
"h1, h2, h3, h4, h5, h6, p, label, button, input, textarea, select, [role='button'], [role='checkbox'], [role='combobox'], [role='slider'], [role='textbox']",
40+
),
41+
)
42+
const clippedTextCandidates = Array.from(element.querySelectorAll<HTMLElement>("span, div")).filter((candidate) => {
43+
const styles = getComputedStyle(candidate)
44+
const hasDirectText = Array.from(candidate.childNodes).some(
45+
(node) => node.nodeType === Node.TEXT_NODE && Boolean(node.textContent?.trim()),
46+
)
47+
return (
48+
hasDirectText &&
49+
(styles.overflowX === "hidden" ||
50+
styles.overflowX === "clip" ||
51+
styles.overflowY === "hidden" ||
52+
styles.overflowY === "clip" ||
53+
styles.textOverflow === "ellipsis")
54+
)
55+
})
56+
const candidates = [...new Set([...semanticCandidates, ...clippedTextCandidates])].filter(
57+
(candidate) => candidate.getClientRects().length > 0 && !isScreenReaderOnly(candidate),
58+
)
59+
60+
const failures: string[] = []
61+
if (document.documentElement.scrollWidth > viewportWidth + tolerance)
62+
failures.push("document overflows horizontally")
63+
if (document.body.scrollWidth > viewportWidth + tolerance) failures.push("body overflows horizontally")
64+
if (element.scrollWidth > element.clientWidth + tolerance) failures.push("root overflows horizontally")
65+
66+
for (const candidate of candidates) {
67+
const rect = candidate.getBoundingClientRect()
68+
const styles = getComputedStyle(candidate)
69+
const name =
70+
candidate.getAttribute("aria-label") || candidate.textContent?.trim().slice(0, 40) || candidate.tagName
71+
if (rect.left < -tolerance || rect.right > viewportWidth + tolerance) failures.push(`${name} leaves viewport`)
72+
if (
73+
(styles.overflowX === "hidden" || styles.overflowX === "clip") &&
74+
candidate.scrollWidth > candidate.clientWidth + tolerance
75+
) {
76+
failures.push(`${name} clips horizontally`)
77+
}
78+
if (
79+
(styles.overflowY === "hidden" || styles.overflowY === "clip") &&
80+
candidate.scrollHeight > candidate.clientHeight + tolerance
81+
) {
82+
failures.push(`${name} clips vertically`)
83+
}
84+
85+
let ancestor = candidate.parentElement
86+
while (ancestor && element.contains(ancestor)) {
87+
const ancestorStyles = getComputedStyle(ancestor)
88+
const clipsX = ancestorStyles.overflowX === "hidden" || ancestorStyles.overflowX === "clip"
89+
const clipsY = ancestorStyles.overflowY === "hidden" || ancestorStyles.overflowY === "clip"
90+
if (clipsX || clipsY) {
91+
const ancestorRect = ancestor.getBoundingClientRect()
92+
if (
93+
clipsX &&
94+
(rect.left < ancestorRect.left - tolerance || rect.right > ancestorRect.right + tolerance)
95+
)
96+
failures.push(`${name} is clipped horizontally by an ancestor`)
97+
if (
98+
clipsY &&
99+
(rect.top < ancestorRect.top - tolerance || rect.bottom > ancestorRect.bottom + tolerance)
100+
)
101+
failures.push(`${name} is clipped vertically by an ancestor`)
102+
}
103+
ancestor = ancestor.parentElement
104+
}
105+
}
106+
return failures
107+
}
108+
17109
export async function expectBoundedLayout(
18110
page: Page,
19111
root: Locator,
@@ -31,72 +123,7 @@ export async function expectBoundedLayout(
31123
document.head.append(style)
32124
}, WCAG_TEXT_SPACING)
33125

34-
await expect
35-
.poll(() =>
36-
root.evaluate((element) => {
37-
const tolerance = 1
38-
const viewportWidth = document.documentElement.clientWidth
39-
const candidates = Array.from(
40-
element.querySelectorAll<HTMLElement>(
41-
"h1, h2, h3, h4, h5, h6, p, label, button, input, textarea, select, [role='button'], [role='checkbox'], [role='combobox'], [role='slider'], [role='textbox']",
42-
),
43-
).filter((candidate) => candidate.getClientRects().length > 0)
44-
45-
const failures: string[] = []
46-
if (document.documentElement.scrollWidth > viewportWidth + tolerance)
47-
failures.push("document overflows horizontally")
48-
if (document.body.scrollWidth > viewportWidth + tolerance) failures.push("body overflows horizontally")
49-
if (element.scrollWidth > element.clientWidth + tolerance) failures.push("root overflows horizontally")
50-
51-
for (const candidate of candidates) {
52-
const rect = candidate.getBoundingClientRect()
53-
const styles = getComputedStyle(candidate)
54-
const name =
55-
candidate.getAttribute("aria-label") ||
56-
candidate.textContent?.trim().slice(0, 40) ||
57-
candidate.tagName
58-
if (rect.left < -tolerance || rect.right > viewportWidth + tolerance)
59-
failures.push(`${name} leaves viewport`)
60-
if (
61-
(styles.overflowX === "hidden" || styles.overflowX === "clip") &&
62-
candidate.scrollWidth > candidate.clientWidth + tolerance
63-
) {
64-
failures.push(`${name} clips horizontally`)
65-
}
66-
if (
67-
(styles.overflowY === "hidden" || styles.overflowY === "clip") &&
68-
candidate.scrollHeight > candidate.clientHeight + tolerance
69-
) {
70-
failures.push(`${name} clips vertically`)
71-
}
72-
73-
let ancestor = candidate.parentElement
74-
while (ancestor && element.contains(ancestor)) {
75-
const ancestorStyles = getComputedStyle(ancestor)
76-
const clipsX = ancestorStyles.overflowX === "hidden" || ancestorStyles.overflowX === "clip"
77-
const clipsY = ancestorStyles.overflowY === "hidden" || ancestorStyles.overflowY === "clip"
78-
if (clipsX || clipsY) {
79-
const ancestorRect = ancestor.getBoundingClientRect()
80-
if (
81-
clipsX &&
82-
(rect.left < ancestorRect.left - tolerance ||
83-
rect.right > ancestorRect.right + tolerance)
84-
)
85-
failures.push(`${name} is clipped horizontally by an ancestor`)
86-
if (
87-
clipsY &&
88-
(rect.top < ancestorRect.top - tolerance ||
89-
rect.bottom > ancestorRect.bottom + tolerance)
90-
)
91-
failures.push(`${name} is clipped vertically by an ancestor`)
92-
}
93-
ancestor = ancestor.parentElement
94-
}
95-
}
96-
return failures
97-
}),
98-
)
99-
.toEqual([])
126+
await expect.poll(() => root.evaluate(collectBoundedLayoutFailures)).toEqual([])
100127

101128
for (const actionRow of actionRows) {
102129
const containment = await actionRow.evaluate((row) => {

‎webview-ui/src/components/chat/ChatTextArea.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
12881288
)}
12891289

12901290
<div className="flex items-center gap-2">
1291-
<div className="flex items-center gap-2 min-w-0 overflow-clip flex-1">
1291+
<div className="flex items-center gap-2 min-w-0 overflow-clip flex-1 min-[310px]:flex-wrap min-[310px]:overflow-visible">
12921292
<ModeSelector
12931293
value={mode}
12941294
title={t("chat:selectMode")}
@@ -1304,14 +1304,14 @@ export const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
13041304
disabled={selectApiConfigDisabled}
13051305
title={t("chat:selectApiConfig")}
13061306
onChange={handleApiConfigChange}
1307-
triggerClassName="min-w-[28px] text-ellipsis overflow-hidden flex-shrink"
1307+
triggerClassName="min-w-[28px] text-ellipsis overflow-hidden flex-shrink min-[310px]:min-w-fit min-[310px]:overflow-visible min-[310px]:flex-shrink-0"
13081308
listApiConfigMeta={listApiConfigMeta || []}
13091309
pinnedApiConfigs={pinnedApiConfigs}
13101310
togglePinnedApiConfig={togglePinnedApiConfig}
13111311
lockApiConfigAcrossModes={!!lockApiConfigAcrossModes}
13121312
onToggleLockApiConfig={handleToggleLockApiConfig}
13131313
/>
1314-
<AutoApproveDropdown triggerClassName="min-w-[28px] text-ellipsis overflow-hidden flex-shrink" />
1314+
<AutoApproveDropdown triggerClassName="min-w-[28px] text-ellipsis overflow-hidden flex-shrink min-[310px]:overflow-visible min-[310px]:flex-shrink-0" />
13151315
</div>
13161316
<div className={cn("flex flex-shrink-0 items-center gap-0.5 h-5 leading-none pr-2")}>
13171317
{isTtsPlaying && (

‎webview-ui/src/components/history/HistoryView.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
156156
/>
157157
)}
158158
</VSCodeTextField>
159-
<div className="flex gap-2">
159+
<div className="grid grid-cols-1 min-[400px]:grid-cols-2 gap-2">
160160
<Select
161161
value={showAllWorkspaces ? "all" : "current"}
162162
onValueChange={(value) => setShowAllWorkspaces(value === "all")}>
163-
<SelectTrigger className="min-w-0 flex-1">
163+
<SelectTrigger className="w-full min-w-0">
164164
<SelectValue>
165165
{t("history:workspace.prefix")}{" "}
166166
{t(`history:workspace.${showAllWorkspaces ? "all" : "current"}`)}
@@ -182,7 +182,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
182182
</SelectContent>
183183
</Select>
184184
<Select value={sortOption} onValueChange={(value) => setSortOption(value as SortOption)}>
185-
<SelectTrigger className="min-w-0 flex-1">
185+
<SelectTrigger className="w-full min-w-0">
186186
<SelectValue>
187187
{t("history:sort.prefix")} {t(`history:sort.${sortOption}`)}
188188
</SelectValue>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect, test } from "../../../../playwright/coverage-fixture"
2+
import { collectBoundedLayoutFailures } from "../../../../playwright/layout-contracts"
3+
import { mountedStory } from "../../../../playwright/mounted-story"
4+
5+
test("detects clipped direct text containers", async ({ mount }) => {
6+
const component = mountedStory(await mount("layout-clipped-text"))
7+
const failures = await component.evaluate(collectBoundedLayoutFailures)
8+
9+
expect(failures).toContain("Clipped direct text clips horizontally")
10+
})
11+
12+
test("ignores screen-reader-only content", async ({ mount }) => {
13+
const component = mountedStory(await mount("layout-screen-reader-only"))
14+
const failures = await component.evaluate(collectBoundedLayoutFailures)
15+
16+
expect(failures).toEqual([])
17+
})

0 commit comments

Comments
 (0)