A local-first multi-agent app development platform, built on PenguinHarness
fix(ui): list rows keep their actions in view, however long their text
lmlihengc5b9ab375c8d
diff --git a/changelog/unreleased/2026-10-17-list-row-actions-visible.md b/changelog/unreleased/2026-10-17-list-row-actions-visible.mdnew file mode 100644index 00000000..0fb1a23f--- /dev/null+++ b/changelog/unreleased/2026-10-17-list-row-actions-visible.md@@ -0,0 +1,26 @@+# List rows keep their actions in view, however long their text++- **Date:** 2026-10-17+- **Type:** fix+- **Scope:** `ui`, `ui-gallery`++[中文版](2026-10-17-list-row-actions-visible.zh.md)++Ported from upstream PenguinHarness (#1157, commit `ef12d442`), together with one layout hunk of `#1133` (`5d01f6a4`) that #1157 rests on and this fork had not taken.++In Agent settings → Memory, upstream found that one memory with a long description laid every row of its section out wider than the card, so the card clipped the view, edit and delete buttons on every row, the short rows' too; a longer description pushed the date off as well. The fix sits in the shared list row and the collapsible section (`packages/ui`), so every list built on them holds the same way.++## Details++- `CollapsibleSection` holds its body to the card's width (`min-width: 0` on the fold's grid item, as `Fold` already did). Its body's `auto` column grew to the item's minimum width, where a line that truncates with `nowrap` counts at its full length.+- `ListRow` no longer asks its container for its text's width: title and description sit in a one-column `minmax(0, 1fr)` grid, so a row's narrowest width is its mark, date and actions, whatever container it is in. Title and description still truncate to one line each and show whole on hover.+- The meta and the actions keep their width and take a line of their own once they no longer fit beside the text (`flex-wrap` on the row, `basis-40` on the text, and one wrapping, right-aligned group holding the date and the actions). That layout came with `#1133`; #1157's own gallery check measures it at the largest text size, where three action buttons in a 220 px card are otherwise clipped.+- `ListRow` puts at most 1,000 characters of a string title or description on the page, ending in an ellipsis, and carries the whole string in the line's hover hint, so a description of any length costs a row the layout of a thousand characters at most.+- The component library's data board gained a section of memory rows with very long text, and the gallery a Playwright check (`pnpm --filter @lmliheng/penguin-ui-gallery test:e2e`) that measures every row and action against its card in each theme and language at the board's width and narrowed to 360, 280 and 220 px. The gallery keeps that spec out of vitest by scoping vitest to `test/**/*.test.ts`.+- Two assertions in `test/list-row.test.ts` follow the row's new markup: its own class string, and the date and the actions sitting in their own group outside the opening button.++## Differences in this fork++- The fold still clips on the body box (`overflow-hidden`), not on the grid (`overflow-clip`, which arrived with a later upstream change this fork has not taken). `overflow: hidden` already zeroes that item's automatic minimum size, so this tree never showed upstream's symptom of the *card* growing wide: on a real server and browser (Agent settings → Memory, three memories, two of them with descriptions of several hundred characters) the rows and their actions stay inside the card in both states at 1280 / 1024 / 768 / 390 / 320 px. What the port changes here is the width a row *asks for* — its min-content drops from 5417 / 5576 / 513 px to 120 px, and from 6759 / 6958 / 629 px to 138 px at 390 px with the largest text size.+- `ListRow` has no `SettingsList` sibling here (that arrived with upstream's Workbench work, which this fork has not taken), so the port adds the row's own changes alone.+- The gallery's example memory that quotes a version names Adelie, not the upstream product.diff --git a/changelog/unreleased/2026-10-17-list-row-actions-visible.zh.md b/changelog/unreleased/2026-10-17-list-row-actions-visible.zh.mdnew file mode 100644index 00000000..493b9939--- /dev/null+++ b/changelog/unreleased/2026-10-17-list-row-actions-visible.zh.md@@ -0,0 +1,26 @@+# 列表行的操作始终可见,无论文字多长++- **Date:** 2026-10-17+- **Type:** fix+- **Scope:** `ui`, `ui-gallery`++[English](2026-10-17-list-row-actions-visible.md)++移植自上游 PenguinHarness(#1157,提交 `ef12d442`),并一并落下 #1157 所依赖、本 fork 还没取的 `#1133`(`5d01f6a4`)里那一段列表行布局。++上游的原始报告:在 Agent 设置 → 记忆中,只要有一条记忆的说明很长,所在分组的每一行都会排得比卡片更宽,卡片于是把每一行的查看、编辑、删除按钮都裁掉了,说明很短的行也不例外;说明再长一些,连日期也会被挤出去。修复落在 `packages/ui` 的共享列表行与可折叠分组上,所有基于它们的列表都随之生效。++## 细节++- `CollapsibleSection` 把分组主体限制在卡片宽度内(折叠网格的子项设 `min-width: 0`,与 `Fold` 的做法一致)。此前主体的 `auto` 列会撑到子项的最小宽度,而截断的行用 `nowrap`,最小宽度按文字的完整长度算。+- `ListRow` 不再按文字宽度向容器要空间:标题与说明放在单列 `minmax(0, 1fr)` 网格里,因此一行最窄只需容下标志、日期与操作,不论放在什么容器中。标题与说明仍各截成一行、悬停显示全文。+- 日期与操作保持原有宽度,放不下时整组换到文字下方(行上 `flex-wrap`、文字上 `basis-40`,日期与操作收进一个可换行、右对齐的组)。这段布局来自 `#1133`;#1157 自带的 gallery 检查正是在最大字号下量它 —— 少了它,220 px 宽的卡片会把三个操作按钮裁掉。+- `ListRow` 对字符串形式的标题或说明最多只放 1,000 个字符到页面上,末尾加省略号,完整文字放进该行的悬停提示;说明再长,一行的排版开销也至多相当于一千个字符。+- 组件库的数据看板新增一组带超长文字的记忆行;gallery 新增 Playwright 检查(`pnpm --filter @lmliheng/penguin-ui-gallery test:e2e`),在每个主题与语言下、于看板原宽及收窄到 360 / 280 / 220 px 时,逐一量出每行与每个操作是否都在卡片之内。该 spec 不归 vitest:gallery 的 vitest 收窄到 `test/**/*.test.ts`。+- `test/list-row.test.ts` 里两条既有断言跟着新的标记走:行自己的类名字符串、以及日期与操作位于那个组里、仍在开合按钮之外。++## 本 fork 的差异++- 折叠仍然裁在主体那一格(`overflow-hidden`),而不是上游后来的「裁在网格上」(`overflow-clip`,本 fork 还没取那一笔)。而 `overflow: hidden` 本来就把那一格的最小尺寸归零,所以本树从未出现上游那个「卡片被撑宽」的现象:在真服务端 + 真浏览器上(Agent 设置 → 记忆,三条记忆、其中两条的说明各几百字),1280 / 1024 / 768 / 390 / 320 px 下两态的行与操作都落在卡片之内。本笔在本树改变的是**一行向容器要多少宽度** —— 行的 min-content 从 5417 / 5576 / 513 px 降到 120 px,在 390 px 宽 + 最大字号下从 6759 / 6958 / 629 px 降到 138 px。+- 本树的 `ListRow` 旁边没有 `SettingsList`(它随上游的 Workbench 一起进来,本 fork 未取),所以这次只落列表行本身的改动。+- gallery 里那条带版本号的示例记忆写的是 Adelie,不是上游产品名。diff --git a/packages/ui-gallery/e2e/list-row-width.spec.mjs b/packages/ui-gallery/e2e/list-row-width.spec.mjsnew file mode 100644index 00000000..25e9e2f0--- /dev/null+++ b/packages/ui-gallery/e2e/list-row-width.spec.mjs@@ -0,0 +1,139 @@+/**+ * List rows never push their actions out of their card.+ *+ * The component library's data board (`lib.html?topic=data`) holds a collapsible section of+ * memory rows, as Agent settings lists them: a long id, a description that runs far past any+ * card, a date and three icon actions, beside a short row. A line that truncates with `nowrap`+ * counts at its full length in a container's minimum width; once, one such row widened the+ * section's body past the card, so every row ran off its edge and the card clipped each row's+ * actions, the short rows' too.+ *+ * - Given each theme, both languages and the largest text size, at the board's width and with+ * the section narrowed to 360, 280 and 220 px, every row and every action lies inside the+ * card, every title and description either fits or is cut off by its own box, and the page+ * never scrolls sideways.+ * - Given rows whose text is longer than any card, asked how narrow it can be, a row needs no+ * more than its date and its actions: it never asks its container for its text's width.+ * - Given a description cut off at the row's end, hovering it shows the whole text.+ */+import { test, expect } from "@playwright/test";++const TITLE = { en: "User memory", zh: "用户记忆" };+const THEMES = ["modern", "geek", "github"];+const NARROWED = [360, 280, 220];++/** Opens the data board and returns the memory section. */+async function openSection(page, { theme, lang, size = "m", mode = "light" }) {+ await page.goto(`/lib.html?topic=data&theme=${theme}&mode=${mode}&lang=${lang}&size=${size}`);+ // The section is the card around its fold toggle (the board's own group is a section too).+ const section = page+ .getByRole("button", { name: new RegExp(TITLE[lang]) })+ .locator("xpath=ancestor::section[1]");+ await expect(section.locator("li")).toHaveCount(3);+ return section;+}++/**+ * What lies out of place in the section, in client pixels: a row or an action past the card's+ * inner box, a line drawn past its own box, the page wider than the window.+ */+const misplaced = (section) =>+ section.evaluate((card) => {+ const out = [];+ const box = card.getBoundingClientRect();+ const style = getComputedStyle(card);+ const left = box.left + parseFloat(style.borderLeftWidth) - 0.5;+ const right = box.right - parseFloat(style.borderRightWidth) + 0.5;+ const outside = (el) => {+ const r = el.getBoundingClientRect();+ return r.left < left || r.right > right;+ };+ for (const [i, row] of [...card.querySelectorAll("li")].entries()) {+ if (outside(row)) out.push(`row ${i} runs past the card`);+ for (const action of row.querySelectorAll("button")) {+ if (outside(action)) out.push(`row ${i}: "${action.ariaLabel}" is clipped by the card`);+ }+ for (const line of row.querySelectorAll("*")) {+ const lineStyle = getComputedStyle(line);+ if (lineStyle.textOverflow !== "ellipsis") continue;+ if (outside(line)) out.push(`row ${i}: a line runs past the card`);+ const spills = line.scrollWidth > line.clientWidth + 1;+ if (spills && !["hidden", "clip"].includes(lineStyle.overflowX)) {+ out.push(`row ${i}: a line paints past its box`);+ }+ }+ }+ const doc = document.documentElement;+ if (doc.scrollWidth > doc.clientWidth) out.push("the page scrolls sideways");+ return out;+ });++/** Every check at the board's width and narrowed, labelled by width. */+async function misplacedAtEveryWidth(section) {+ const found = (await misplaced(section)).map((m) => `board width: ${m}`);+ for (const width of NARROWED) {+ await section.evaluate((card, w) => (card.style.width = `${w}px`), width);+ found.push(...(await misplaced(section)).map((m) => `${width}px: ${m}`));+ }+ await section.evaluate((card) => (card.style.width = ""));+ return found;+}++test.describe("list rows with text longer than their card", () => {+ for (const theme of THEMES) {+ for (const lang of ["en", "zh"]) {+ test(`keep every action inside the card at every width (${theme}, ${lang})`, async ({+ page,+ }) => {+ const section = await openSection(page, { theme, lang });+ expect(await misplacedAtEveryWidth(section)).toEqual([]);+ });+ }+ }++ test("keep every action inside the card at the largest text size, in dark", async ({ page }) => {+ const section = await openSection(page, {+ theme: "github",+ lang: "zh",+ size: "xl",+ mode: "dark",+ });+ expect(await misplacedAtEveryWidth(section)).toEqual([]);+ });++ test("never ask their container for their text's width", async ({ page }) => {+ const section = await openSection(page, { theme: "github", lang: "en", size: "xl" });+ const rows = await section.locator("li").evaluateAll((items) =>+ items.map((row) => {+ const saved = row.style.width;+ row.style.width = "min-content";+ const narrowest = row.getBoundingClientRect().width;+ row.style.width = "max-content";+ const widest = row.getBoundingClientRect().width;+ row.style.width = saved;+ const trailing = row.lastElementChild.getBoundingClientRect().width;+ return { narrowest, widest, trailing };+ }),+ );+ for (const row of rows) {+ // Its text is longer than any card: laid out whole, the row is far wider than this.+ expect(row.widest).toBeGreaterThan(600);+ // Asked for its narrowest, it keeps only the date and the actions (plus its padding).+ expect(row.narrowest).toBeLessThanOrEqual(row.trailing + 48);+ }+ });++ test("show a cut-off description whole on hover", async ({ page }) => {+ const section = await openSection(page, { theme: "github", lang: "en" });+ const description = section.getByText(/^The local proxy listens/);+ const whole = (await description.textContent()).trim();+ expect(await description.evaluate((el) => el.scrollWidth > el.clientWidth)).toBe(true);+ // Any scroll closes a hint, so the scroll that brings the row into view lands first.+ await description.scrollIntoViewIfNeeded();+ await page.evaluate(+ () => new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done))),+ );+ await description.hover();+ await expect(page.getByTestId("tooltip")).toHaveText(whole);+ });+});diff --git a/packages/ui-gallery/e2e/playwright.config.mjs b/packages/ui-gallery/e2e/playwright.config.mjsnew file mode 100644index 00000000..05dd9ff7--- /dev/null+++ b/packages/ui-gallery/e2e/playwright.config.mjs@@ -0,0 +1,31 @@+/**+ * Browser checks against the component library: layout that only a real engine can measure.+ *+ * pnpm --filter @lmliheng/penguin-ui-gallery test:e2e+ *+ * Starts the gallery's dev server, or reuses one already answering on the port outside CI.+ * `GALLERY_PORT` moves it off the gallery's fixed 7372, for a machine where another checkout's+ * gallery may already hold that port (a reused server would be testing the other checkout).+ * Needs Playwright's Chromium: `pnpm --filter @lmliheng/penguin-ui-gallery exec playwright+ * install chromium`.+ */+import { defineConfig } from "@playwright/test";+import { fileURLToPath } from "node:url";++const PORT = Number(process.env.GALLERY_PORT ?? 7372);+const BASE = `http://localhost:${PORT}`;++export default defineConfig({+ testDir: ".",+ timeout: 60_000,+ expect: { timeout: 10_000 },+ reporter: [["list"]],+ use: { baseURL: BASE, headless: true, trace: "retain-on-failure" },+ webServer: {+ command: `pnpm exec vite --port ${PORT}`,+ cwd: fileURLToPath(new URL("..", import.meta.url)),+ url: `${BASE}/lib.html`,+ reuseExistingServer: !process.env.CI,+ timeout: 120_000,+ },+});diff --git a/packages/ui-gallery/package.json b/packages/ui-gallery/package.jsonindex 55e58927..c2a64bb9 100644--- a/packages/ui-gallery/package.json+++ b/packages/ui-gallery/package.json@@ -10,6 +10,7 @@"preview": "vite preview","typecheck": "tsc --noEmit -p tsconfig.json","test": "vitest run --passWithNoTests",+ "test:e2e": "playwright test -c e2e/playwright.config.mjs","shots": "node scripts/shots.mjs"},"dependencies": {diff --git a/packages/ui-gallery/src/library/boards/data.tsx b/packages/ui-gallery/src/library/boards/data.tsxindex a1dd5d3e..db402a9d 100644--- a/packages/ui-gallery/src/library/boards/data.tsx+++ b/packages/ui-gallery/src/library/boards/data.tsx@@ -1,7 +1,7 @@/*** 数据: the table framed on its own and bare inside a card at the small density, list rows plain- * and opening what they name, label/value pairs at both rungs, and a running job's log — all from- * the package.+ * and opening what they name, rows whose text runs far past a narrow card, label/value pairs at+ * both rungs, and a running job's log — all from the package.*/import {AgentAvatar,@@ -9,6 +9,7 @@ import {Button,Card,CardHeader,+ CollapsibleSection,GlyphIcon,ICONS,ICON_SIZE,@@ -35,6 +36,15 @@ const SCHEDULES = [];const SPEND = ["$12.40", "$8.75", "$3.10"];const SKILLS = ["pdf", "web-design", "continual-learning"];+/** Memory ids and dates; the second id runs long on purpose, as a title that must truncate. */+const MEMORIES = [+ { id: "local-proxy-noninteractive-shell-bypass", date: "2026-10-15" },+ {+ id: "penguinharness-0215-gemini-fetch-mismatch-inside-the-bundled-server-process-only",+ date: "2026-10-13",+ },+ { id: "verify-patents-and-literature-before-citing", date: "2026-10-15" },+];const ROOT = "~/.penguin/data";const MACHINE_ID = "m_7f3a9c21";const LOG = [@@ -133,6 +143,36 @@ export function DataBoard() {</Card></div></BoardGroup>+ <BoardGroup title={t.longRows} aside={t.longRowsHint}>+ <div className="lib-stack">+ <CollapsibleSection title={t.memoryTitle} meta={t.memoryCount(MEMORIES.length)}>+ <ul>+ {MEMORIES.map((memory, i) => (+ <ListRow+ key={memory.id}+ as="li"+ title={<span className="font-mono">{memory.id}</span>}+ description={t.memoryDescriptions[i]}+ meta={<span className="tabular-nums">{memory.date}</span>}+ trailing={+ <>+ <IconButton label={t.viewMemory(memory.id)}>+ <GlyphIcon d={ICONS.eye} size={ICON_SIZE.iconButton} />+ </IconButton>+ <IconButton label={t.editMemory(memory.id)}>+ <GlyphIcon d={ICONS.penLine} size={ICON_SIZE.iconButton} />+ </IconButton>+ <IconButton variant="danger" label={t.deleteMemory(memory.id)}>+ <GlyphIcon d={ICONS.trash} size={ICON_SIZE.iconButton} />+ </IconButton>+ </>+ }+ />+ ))}+ </ul>+ </CollapsibleSection>+ </div>+ </BoardGroup><BoardGroup title={t.keyValue}><div className="lib-row"><Card>diff --git a/packages/ui-gallery/src/strings-en.ts b/packages/ui-gallery/src/strings-en.tsindex 3a9fdbc5..430d9e58 100644--- a/packages/ui-gallery/src/strings-en.ts+++ b/packages/ui-gallery/src/strings-en.ts@@ -1085,6 +1085,19 @@ export const en: GalleryStrings = {"First commit in an empty repository","Truncating a very long file name",],+ longRows: "Long text",+ longRowsHint:+ "Title and description truncate to one line each and show whole on hover; the date and the actions keep their width, wrap under the text when they no longer fit, and are never clipped by the card.",+ memoryTitle: "User memory",+ memoryCount: (n: number) => `${n} items`,+ memoryDescriptions: [+ "The local proxy listens on 127.0.0.1:9090, but ~/.bashrc returns early in a non-interactive shell, so exec_command never sees http_proxy and the rest of the proxy variables; export the proxy in the command itself or pass --noproxy '*' for local addresses, or curl answers 502 for a local port.",+ 'Inside the Adelie 0.2.15 server process every Gemini model call fails with "Failed to parse URL from [object Request]": the bundled fetch and Request disagree. Upgrading to 0.2.16 fixes it.',+ "Verify patent numbers and papers with a tool before citing them.",+ ],+ viewMemory: (name: string) => `View ${name}`,+ editMemory: (name: string) => `Edit ${name}`,+ deleteMemory: (name: string) => `Delete ${name}`,keyValue: "Label and value",labels: {version: "Version",diff --git a/packages/ui-gallery/src/strings.ts b/packages/ui-gallery/src/strings.tsindex c93efb23..b332adc0 100644--- a/packages/ui-gallery/src/strings.ts+++ b/packages/ui-gallery/src/strings.ts@@ -1027,6 +1027,19 @@ export const zh = {exportSkill: (name: string) => `导出 ${name}`,clickable: "打开所指内容的行",cases: ["登录页的表单校验", "空仓库的首次提交", "超长文件名的截断"],+ longRows: "超长文字",+ longRowsHint:+ "标题与说明各截成一行,悬停显示全文;日期与操作保持原宽,放不下时换到文字下方,从不被卡片裁掉。",+ memoryTitle: "用户记忆",+ memoryCount: (n: number) => `${n} 条`,+ memoryDescriptions: [+ "本机代理在 127.0.0.1:9090,但 ~/.bashrc 在非交互式 shell 里提前 return,exec_command 拿不到 http_proxy 等环境变量;需要在命令里显式 export 代理,或对本地地址加 --noproxy '*',否则 curl 访问本地端口会返回 502。",+ 'Adelie 0.2.15 服务器进程内调用任何 Gemini 模型都会失败:"Failed to parse URL from [object Request]"。原因是打包后的 fetch 与 Request 实现不一致,升级到 0.2.16 后恢复正常。',+ "引用专利号或文献前,先用工具核验。",+ ],+ viewMemory: (name: string) => `查看 ${name}`,+ editMemory: (name: string) => `编辑 ${name}`,+ deleteMemory: (name: string) => `删除 ${name}`,keyValue: "键值对",labels: {version: "版本",diff --git a/packages/ui-gallery/vitest.config.ts b/packages/ui-gallery/vitest.config.tsindex 30c71389..31764127 100644--- a/packages/ui-gallery/vitest.config.ts+++ b/packages/ui-gallery/vitest.config.ts@@ -3,12 +3,13 @@* this package's vite 7 plugin types). A node environment suffices: the tests cover the* gallery's pure modules and the demo store, which never touches the DOM. The network swap* plugin is applied here too, so a test can import the Web App's endpoint wrappers and drive- * them against the mock — that is how the coverage test walks every endpoint.+ * them against the mock — that is how the coverage test walks every endpoint. The browser checks+ * under e2e/ are Playwright's (`test:e2e`), not vitest's.*/import { defineConfig } from "vitest/config";import { mockWebNetwork } from "./src/app/mock/vite-plugin";export default defineConfig({plugins: [mockWebNetwork()],- test: { environment: "node" },+ test: { environment: "node", include: ["test/**/*.test.ts"] },});diff --git a/packages/ui/src/components/data/list-row/list-row.tsx b/packages/ui/src/components/data/list-row/list-row.tsxindex 8ddc468d..74809d89 100644--- a/packages/ui/src/components/data/list-row/list-row.tsx+++ b/packages/ui/src/components/data/list-row/list-row.tsx@@ -4,10 +4,53 @@* one and lighten under the pointer, so a row's actions read as its own.** A row that opens what it names takes `onClick`: the mark and the text become one button, and- * the trailing actions stay outside it, since a button cannot hold another. Title and description- * truncate to one line each; the caller puts the whole text in a tooltip where it matters.+ * the trailing actions stay outside it, since a button cannot hold another.+ *+ * The text gives way and the actions never do. Title and description truncate to one line each,+ * whatever their length, and a cut-off line shows whole on hover through the app's tooltip layer,+ * which reads the line's own text, so it needs no attribute. The meta and the actions keep their+ * own width; when the row is too narrow for them beside the text they wrap under it, right-aligned,+ * and are never clipped.+ *+ * A string longer than any row can show is cut before it reaches the page ({@link LINE_LIMIT}),+ * ending in an ellipsis, and the line then carries the whole string as its marked hint.+ *+ * That holds in any container because the row never asks for its text's width: the text sits in+ * a one-column `minmax(0, 1fr)` grid, whose min-content width is zero, so the row's min-content+ * width is its mark's and its actions'. A `truncate` line otherwise counts at its full length+ * there, and a container that sizes itself to its content's minimum — a grid's `auto` column (a+ * fold's body), a flex item left at `min-width: auto`, a table cell — grew to the longest line and+ * pushed every row's actions past the card's edge. The row's max-content width still counts the+ * full text, so a box that sizes to fit the row (`w-max`) shows it whole.*/import type { ReactNode } from "react";+/**+ * The most of a string title or description a row puts on the page. Laying out a truncated line+ * still walks all of its text, so a row's relayout costs in proportion to the text's length+ * (Chromium, 100 rows resized: 2 ms at 200 characters, 29 ms at 20 000, 254 ms at 200 000). A+ * thousand characters is more than the widest row shows at the smallest text size.+ */+const LINE_LIMIT = 1000;++/** One line of the row's text: a string past the limit is cut, its whole text the line's hint. */+function RowLine({ className, children }: { className: string; children: ReactNode }) {+ if (typeof children !== "string" || children.length <= LINE_LIMIT) {+ return <span className={className}>{children}</span>;+ }+ // Never end on the first half of a surrogate pair.+ const code = children.charCodeAt(LINE_LIMIT - 1);+ const end = code >= 0xd800 && code <= 0xdbff ? LINE_LIMIT - 1 : LINE_LIMIT;+ return (+ <span+ className={className}+ data-tooltip={children}+ data-tooltip-content="text"+ data-tooltip-extra+ >+ {`${children.slice(0, end)}…`}+ </span>+ );+}export interface ListRowProps {/** A mark before the text: an avatar, a tile, a glyph. */@@ -39,31 +82,41 @@ export function ListRow({const text = (<>{leading !== undefined && <span className="flex shrink-0 items-center">{leading}</span>}- <span className="min-w-0 flex-1">- <span className="block truncate text-sm font-medium text-fg">{title}</span>+ <span className="grid min-w-0 flex-1 grid-cols-1">+ <RowLine className="truncate text-sm font-medium text-fg">{title}</RowLine>{description !== undefined && (- <span className="mt-0.5 block truncate text-xs text-fg-muted">{description}</span>+ <RowLine className="mt-0.5 truncate text-xs text-fg-muted">{description}</RowLine>)}</span></>);return (<Tag- className={`flex items-center gap-3 border-b border-line-muted px-3 py-2.5 transition-colors duration-150 last:border-b-0 hover:bg-surface-muted ${className}`}+ className={`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-line-muted px-3 py-2.5 transition-colors duration-150 last:border-b-0 hover:bg-surface-muted ${className}`}>{onClick !== undefined ? (<buttontype="button"onClick={onClick}- className="flex min-w-0 flex-1 items-center gap-3 text-left"+ className="flex min-w-0 flex-1 basis-40 items-center gap-3 text-left">{text}</button>) : (- <div className="flex min-w-0 flex-1 items-center gap-3">{text}</div>+ <div className="flex min-w-0 flex-1 basis-40 items-center gap-3">{text}</div>+ )}+ {(meta !== undefined || trailing !== undefined) && (+ // The meta and the actions hold their width: `ml-auto` keeps them at the end edge while+ // they fit beside the text, and once the row is too narrow for that they wrap under it as+ // one group — `max-w-full` lets the group wrap inside itself, so three icon buttons still+ // fit a phone, and the row's `flex-wrap` is what lets the group move down at all.+ <div className="ml-auto flex max-w-full flex-wrap items-center justify-end gap-3">+ {meta !== undefined && <span className="text-xs text-fg-subtle">{meta}</span>}+ {trailing !== undefined && (+ <div className="flex flex-wrap items-center justify-end gap-1">{trailing}</div>+ )}+ </div>)}- {meta !== undefined && <span className="shrink-0 text-xs text-fg-subtle">{meta}</span>}- {trailing !== undefined && <div className="flex shrink-0 items-center gap-1">{trailing}</div>}</Tag>);}diff --git a/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx b/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsxindex b024692a..9e8448f4 100644--- a/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx+++ b/packages/ui/src/components/layout/collapsible-section/collapsible-section.tsx@@ -11,6 +11,12 @@* `1fr` to `0fr`, and it carries `data-layout-motion`, so the theme's layout motion moves it (and* nothing does under reduced motion). A component never transitions a size itself.*+ * The body is held to the card's width (`min-w-0`, which is what `Fold` does too). The fold's one+ * column is `auto`, and an `auto` column grows to its item's minimum width — left automatic, the+ * body's min-content width, where a line that truncates with `nowrap` counts at its full length.+ * One long line would make the column wider than the card: every row in the section would run past+ * its edge, and the card would clip each row's actions.+ ** Open or folded is the caller's when it passes `open` (a page that remembers it), the section's* own otherwise, starting from `defaultOpen`.*/@@ -81,7 +87,7 @@ export function CollapsibleSection({data-layout-motionclassName={`grid ${open ? "grid-rows-[1fr]" : "grid-rows-[0fr]"}`}>- <div id={bodyId} className="min-h-0 overflow-hidden" inert={!open}>+ <div id={bodyId} className="min-h-0 min-w-0 overflow-hidden" inert={!open}><div className="border-t border-line-muted">{children}</div></div></div>diff --git a/packages/ui/test/collapsible-section.test.ts b/packages/ui/test/collapsible-section.test.tsindex cc514fc7..a721e24d 100644--- a/packages/ui/test/collapsible-section.test.ts+++ b/packages/ui/test/collapsible-section.test.ts@@ -40,7 +40,7 @@ describe("CollapsibleSection", () => {const folded = render({ defaultOpen: false });expect(folded).toContain('aria-expanded="false"');expect(folded).toMatch(/class="grid grid-rows-\[0fr\]"/);- expect(folded).toMatch(/<div id="[^"]+" class="min-h-0 overflow-hidden" inert="">/);+ expect(folded).toMatch(/<div id="[^"]+" class="min-h-0 min-w-0 overflow-hidden" inert="">/);for (const html of [open, folded]) {expect(classTokens(html).filter((t) => /^transition-\[/.test(t))).toEqual([]);}diff --git a/packages/ui/test/list-row.test.ts b/packages/ui/test/list-row.test.tsindex e7e69dae..c65869e0 100644--- a/packages/ui/test/list-row.test.ts+++ b/packages/ui/test/list-row.test.ts@@ -1,27 +1,88 @@/*** ListRow: a ruled row whose mark and text become one button when the row opens what it names,* with its own actions outside that button.+ *+ * - Given an item with metadata and an action, the row shows them all.+ * - Given a row that opens something, its mark and text are one button and the actions sit+ * outside it.+ * - Given a description far longer than any row can show, the page holds only its beginning,+ * ending in an ellipsis, and the line's hover hint carries all of it — never half a character.+ * - Given a description a row can show, it is rendered whole with no hint of its own (the+ * tooltip layer shows a cut-off line's own text).+ *+ * How rows fit their card at every width is measured in a browser: ui-gallery's+ * e2e/list-row-width.spec.mjs.*/import { createElement } from "react";import { describe, expect, it } from "vitest";import { ListRow } from "../src/components/data/list-row/list-row";+import { tooltipRequest } from "../src/components/overlays/tooltip/tooltip";import { classTokens, renderStatic } from "../src/testing";const trailing = createElement("button", { type: "button", "aria-label": "Export" }, "E");+/**+ * The description line as the page holds it: its text, and the hover hint the tooltip layer reads+ * from it (null when the line carries none and the layer would show its own text).+ */+function descriptionLine(description: string) {+ const html = renderStatic(createElement(ListRow, { title: "memory", description }));+ // The description is the row's last line of text.+ const [, attributes, text] = [...html.matchAll(/<span([^>]*)>([^<]*)<\/span>/g)].at(-1)!;+ const attrs = new Map(+ [...attributes!.matchAll(/([\w-]+)="([^"]*)"/g)].map(([, name, value]) => [name!, value!]),+ );+ return { text: text!, hint: tooltipRequest({ getAttribute: (name) => attrs.get(name) ?? null }) };+}+describe("ListRow", () => {it("is a ruled row that lightens under the pointer, on tokens", () => {const html = renderStatic(createElement(ListRow, { title: "pdf", description: "Reads PDFs.", meta: "2 KB", trailing }),);- expect(html).toMatch(/^<div class="flex items-center gap-3 border-b border-line-muted /);+ expect(html).toMatch(+ /^<div class="flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-line-muted /,+ );expect(classTokens(html)).toEqual(- expect.arrayContaining(["last:border-b-0", "hover:bg-surface-muted", "text-fg-muted"]),+ expect.arrayContaining([+ "last:border-b-0",+ "hover:bg-surface-muted",+ "text-fg-muted",+ // Both the row and the actions group wrap, and the group is free to take a line of its+ // own: that is what keeps the actions in view once they no longer fit beside the text.+ "flex-wrap",+ "ml-auto",+ "max-w-full",+ "basis-40",+ ]),);// Not a button when it opens nothing: the only button is the action.expect(html.match(/<button/g)).toHaveLength(1);});+ it("puts only the beginning of a very long description on the page, the whole of it in the hint", () => {+ const description = "记忆 memory ".repeat(20_000);+ const line = descriptionLine(description);+ expect(line.text.length).toBeLessThan(description.length / 10);+ expect(line.text.endsWith("…")).toBe(true);+ expect(description.startsWith(line.text.slice(0, -1))).toBe(true);+ // Marked: the hint says what the page does not, so it opens over the visible line.+ expect(line.hint).toMatchObject({ label: description, content: "text", extra: true });+ });++ it("never cuts a long description through the middle of a character", () => {+ // A two-unit character, then the same one unit later: one of the two lands across any cut.+ for (const description of ["😀".repeat(100_000), `a${"😀".repeat(100_000)}`]) {+ expect(descriptionLine(description).text).not.toMatch(/\p{Cs}/u);+ }+ });++ it("renders a description a row can show whole, with no hint of its own", () => {+ const line = descriptionLine("Reads PDFs and fills in their forms.");+ expect(line.text).toBe("Reads PDFs and fills in their forms.");+ expect(line.hint).toBeNull();+ });+it("makes the mark and the text one button when it opens something, the actions outside it", () => {const html = renderStatic(createElement(ListRow, {@@ -35,7 +96,7 @@ describe("ListRow", () => {// React 19's server renderer prepends a preload hint for an eager image; not our markup.expect(html.replace(/^<link rel="preload"[^>]*\/>/, "")).toMatch(/^<li /);expect(html).toMatch(- /<button type="button" class="[^"]*"><span[^>]*><img[^>]*\/><\/span>(?:(?!<\/button>).)*case-01(?:(?!<\/button>).)*<\/button><div[^>]*><button type="button" aria-label="Export">/,+ /<button type="button" class="[^"]*"><span[^>]*><img[^>]*\/><\/span>(?:(?!<\/button>).)*case-01(?:(?!<\/button>).)*<\/button><div class="ml-auto[^"]*"><div[^>]*><button type="button" aria-label="Export">/,);});});