Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

fix(models): keep group actions reachable as icon-only buttons at narrow widths (#296)

Yiru Dong077c5ac53c46
diff --git a/changelog/unreleased/2026-08-18-models-header-icon-actions.md b/changelog/unreleased/2026-08-18-models-header-icon-actions.md
new file mode 100644
index 00000000..d78d3c53
--- /dev/null
+++ b/changelog/unreleased/2026-08-18-models-header-icon-actions.md
@@ -0,0 +1,18 @@
+# Models page group actions stay reachable on narrow rows
+
+- **Date:** 2026-08-18
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#296](https://github.com/Prism-Shadow/penguin-harness/pull/296)
+- **Issue:** [#294](https://github.com/Prism-Shadow/penguin-harness/issues/294)
+
+[中文版](2026-08-18-models-header-icon-actions.zh.md)
+
+The models page's group headers adapted to the width the header row itself has, and every group-level action stayed reachable at every width as an icon-only control.
+
+## Details
+
+- The header row became a size container, so its actions respond to the row's own width rather than the viewport's. The desktop sidebar narrows the content column while the viewport still reports a desktop breakpoint, and at those widths the vendor name and the action labels had overlapped.
+- "Add model", "Set API key for group", "Speed test" and the "Get API key" link shed only their text labels as the row narrowed, keeping their icons; no action is hidden outright any more. The button labels return at the `@3xl` row width and the link's at `@4xl`.
+- Each icon-only control carries an accessible name giving both the action and the vendor, plus a tooltip with the action label. The external link took the external-link glyph already used elsewhere on the page, and a slightly larger hit area while icon-only.
+- The layout end-to-end spec sweeps the models page from 390 to 1920 CSS pixels, asserting that every action is reachable at each width, that labels are visible exactly in the labeled regime, and that the header neither overlaps nor overflows. The expected regime is derived from the row's measured width, since the container thresholds are `rem`-based and follow the environment's root font size.
diff --git a/changelog/unreleased/2026-08-18-models-header-icon-actions.zh.md b/changelog/unreleased/2026-08-18-models-header-icon-actions.zh.md
new file mode 100644
index 00000000..d4eed899
--- /dev/null
+++ b/changelog/unreleased/2026-08-18-models-header-icon-actions.zh.md
@@ -0,0 +1,18 @@
+# 模型页分组操作在窄行下依然可用
+
+- **Date:** 2026-08-18
+- **Type:** fix
+- **Scope:** `web`
+- **PR:** [#296](https://github.com/Prism-Shadow/penguin-harness/pull/296)
+- **Issue:** [#294](https://github.com/Prism-Shadow/penguin-harness/issues/294)
+
+[English](2026-08-18-models-header-icon-actions.md)
+
+模型页的分组标题栏改为按标题行自身的宽度自适应,分组级的每个操作在任何宽度下都保留下来,窄行时变成只有图标的控件。
+
+## 细节
+
+- 标题行成为尺寸容器,其中的操作按这一行自己的宽度响应,而不再看视口宽度。桌面端侧栏会压窄内容列,此时视口报出的仍是桌面断点,而在这些宽度下,厂商名与操作文字曾经互相压字。
+- 行变窄时,「新增模型」「统一配置 API key」「测速」以及「获取 API key」链接只去掉文字标签,图标保留;不再有操作被整个藏起来。按钮的文字在 `@3xl` 行宽处回来,链接的文字在 `@4xl` 处回来。
+- 每个只剩图标的控件都带有可访问名称,其中同时给出操作和厂商,另有一个写着操作名称的悬浮提示。外链取用页面上原有的外链图标,并在只剩图标时略微放大点击区域。
+- 布局端到端用例在 390 到 1920 CSS 像素之间扫过模型页,逐一断言每个操作在各宽度下都可达、文字标签恰好只在带标签的档位可见,以及标题行既不压字也不溢出。预期档位由实测的行宽推导,因为容器阈值以 `rem` 为单位,会随运行环境的根字号变化。
diff --git a/packages/web/e2e/layout.spec.mjs b/packages/web/e2e/layout.spec.mjs
index 64925ab1..87ff6bf6 100644
--- a/packages/web/e2e/layout.spec.mjs
+++ b/packages/web/e2e/layout.spec.mjs
@@ -10,6 +10,10 @@
* the group-level actions), and its model dialog opts every field out of browser autofill
* (the API-key box used to receive the account's saved password, the box above it the
* username);
+ * - the models group header is a size container (the desktop sidebar narrows it while the
+ * viewport stays wide): narrow rows collapse every group action to an icon-only control
+ * (icon + aria-label + title kept, text label hidden — an action is never hidden outright)
+ * and neither the header nor the page overlaps or overflows at any width;
* - every chat-page dropdown menu, opened at phone widths (375/390), must keep its panel
* inside the viewport and must not shove the page sideways (the model menu used to run
* ~34px off-screen left, the skills menu ~92px off-screen right — with its autofocused
@@ -261,6 +265,131 @@ test("layout: en draft + context gauge + mobile models", async ({ page }) => {
).toBe("rgba(0, 0, 0, 0)");
});
+test("models: group header actions collapse to icons instead of disappearing", async ({ page }) => {
+ await page.addInitScript(() => localStorage.setItem("penguin.lang", "zh"));
+ await provisionAndLogin(page.request, "modelwidthuser", P);
+ await page.setViewportSize({ width: 900, height: 900 });
+ await page.goto(`${BASE}/models`);
+
+ // The 900px viewport still renders the desktop sidebar, leaving only ~560px for a group
+ // header. That is the issue #294 case: viewport breakpoints alone report plenty of room.
+ const openRouter = page.getByRole("button", { name: /OpenRouter \d+ 个模型/ });
+ await openRouter.waitFor();
+
+ // Every group-level action, addressed by its accessible name (aria-label = "action vendor",
+ // stable across widths). Narrow rows must never hide an action: it keeps its icon (with a
+ // title tooltip) and sheds only the visible text label.
+ const actions = [
+ { role: "button", name: "新增模型 OpenRouter", label: "新增模型" },
+ { role: "button", name: "统一配置 API key OpenRouter", label: "统一配置 API key" },
+ { role: "button", name: "测速 OpenRouter", label: "测速" },
+ { role: "link", name: "获取 API key OpenRouter", label: "获取 API key" },
+ ];
+
+ // The expected label regime is derived from the row's measured width against the
+ // container thresholds — @3xl (48rem) admits the button labels, @4xl (56rem) the link
+ // label — because how wide the row is at a given viewport depends on the environment's
+ // root font size (the sidebar, page padding, viewport breakpoints and the thresholds are
+ // all rem-based). A row hugging a threshold (±16px) skips the label assertions; the
+ // coverage checks after the sweep guarantee both extreme regimes were exercised anyway.
+ const seen = { iconOnly: false, fullyLabeled: false };
+ for (const width of [390, 900, 1180, 1280, 1440, 1920]) {
+ await page.setViewportSize({ width, height: 900 });
+ const { rowWidth, rem } = await openRouter.locator("xpath=..").evaluate((header) => {
+ // Container queries resolve against the content box, so strip the row's padding.
+ const s = getComputedStyle(header);
+ return {
+ rowWidth: header.clientWidth - parseFloat(s.paddingLeft) - parseFloat(s.paddingRight),
+ rem: parseFloat(getComputedStyle(document.documentElement).fontSize),
+ };
+ });
+ const regime = (remThreshold) =>
+ Math.abs(rowWidth - remThreshold * rem) <= 16 ? null : rowWidth >= remThreshold * rem;
+ const buttonLabels = regime(48);
+ const linkLabel = regime(56);
+ if (buttonLabels === false && linkLabel === false) seen.iconOnly = true;
+ if (buttonLabels === true && linkLabel === true) seen.fullyLabeled = true;
+
+ for (const { role, name, label } of actions) {
+ const action = page.getByRole(role, { name });
+ await expect(action, `${label} action reachable @${width}`).toBeVisible();
+ await expect(action, `${label} action has a tooltip @${width}`).toHaveAttribute(
+ "title",
+ /.+/,
+ );
+ const expectLabel = role === "link" ? linkLabel : buttonLabels;
+ if (expectLabel === null) continue;
+ const text = action.locator("span", { hasText: label });
+ const icon = action.locator("svg");
+ if (expectLabel) {
+ await expect(text, `${label} label shown @${width}`).toBeVisible();
+ // The link swaps between glyph and text; the buttons keep their glyph alongside.
+ if (role === "link") {
+ await expect(icon, `${label} icon swapped out @${width}`).toBeHidden();
+ }
+ } else {
+ await expect(text, `${label} label hidden @${width}`).toBeHidden();
+ await expect(icon, `${label} icon shown @${width}`).toBeVisible();
+ }
+ }
+ const metrics = await openRouter.locator("xpath=..").evaluate((header) => {
+ const visible = (el) => {
+ for (let node = el; node; node = node.parentElement) {
+ const s = getComputedStyle(node);
+ if (s.display === "none" || s.visibility === "hidden" || Number(s.opacity) <= 0.05) {
+ return false;
+ }
+ if (node === header) break;
+ }
+ return true;
+ };
+ const textRects = [...header.querySelectorAll("*")]
+ .filter(
+ (el) =>
+ visible(el) &&
+ [...el.childNodes].some(
+ (node) => node.nodeType === Node.TEXT_NODE && node.textContent?.trim(),
+ ),
+ )
+ .map((el) => el.getBoundingClientRect())
+ .filter((rect) => rect.width > 1 && rect.height > 1);
+ let overlaps = 0;
+ for (let i = 0; i < textRects.length; i += 1) {
+ for (let j = i + 1; j < textRects.length; j += 1) {
+ const a = textRects[i];
+ const b = textRects[j];
+ if (
+ Math.min(a.right, b.right) - Math.max(a.left, b.left) > 2 &&
+ Math.min(a.bottom, b.bottom) - Math.max(a.top, b.top) > 2
+ ) {
+ overlaps += 1;
+ }
+ }
+ }
+ const providerLabel = header.querySelector("button span");
+ return {
+ clientWidth: header.clientWidth,
+ scrollWidth: header.scrollWidth,
+ providerWidth: providerLabel?.getBoundingClientRect().width ?? 0,
+ overlaps,
+ };
+ });
+
+ expect(metrics.scrollWidth, `header @${width} has no overflow`).toBeLessThanOrEqual(
+ metrics.clientWidth,
+ );
+ expect(metrics.providerWidth, `provider label @${width} remains visible`).toBeGreaterThan(0);
+ expect(metrics.overlaps, `header @${width} has no overlapping text`).toBe(0);
+ const d = await docWidths(page);
+ expect(d.scrollWidth, `models page @${width} has no overflow`).toBeLessThanOrEqual(
+ d.clientWidth,
+ );
+ }
+
+ expect(seen.iconOnly, "the sweep exercised the icon-only regime").toBe(true);
+ expect(seen.fullyLabeled, "the sweep exercised the fully-labeled regime").toBe(true);
+});
+
test("layout: collapsed rail — order, bilingual tooltips, last conversation", async ({ page }) => {
await page.addInitScript(() => localStorage.setItem("penguin.lang", "en"));
await provisionAndLogin(page.request, "railuser", P);
diff --git a/packages/web/src/features/models/models-page.tsx b/packages/web/src/features/models/models-page.tsx
index 4a4816fc..fb8811ca 100644
--- a/packages/web/src/features/models/models-page.tsx
+++ b/packages/web/src/features/models/models-page.tsx
@@ -124,10 +124,12 @@ function inputToUsd(inputStr: string, currency: Currency): string {
return currency === "CNY" ? trimNum(n / USD_TO_CNY) : trimNum(n);
}
-/** Group-header action glyphs (24x24 line paths): add, bulk key, gauge for speed test. */
+/** Group-header action glyphs (24x24 line paths): add, bulk key, external link, gauge for speed test. */
const PLUS_ICON = "M12 5v14M5 12h14";
const KEY_ICON =
"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4";
+const EXTERNAL_LINK_ICON =
+ "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14 21 3";
/** Speed-test glyphs (24x24 line paths): gauge for the group action, clock = TTFT, zap = TPS. */
const GAUGE_ICON = "M12 14l3.5-3.5M20.49 17A10 10 0 1 0 3.5 17";
@@ -609,11 +611,13 @@ export function ModelsPage() {
className="overflow-hidden rounded-md border border-gray-200 bg-white dark:border-gray-800 dark:bg-gray-900"
>
{/* Group header: collapse button (logo + vendor name + count) + group-level
- actions on the right (bulk configure key, get-key link). Actions are
- separate elements — can't be nested inside the collapse button (buttons
- can't nest). The hover highlight applies to the whole header row (not
- individual buttons) so the header reads as a single unit. */}
- <div className="flex items-center gap-2 bg-gray-50 pr-2 transition-colors duration-150 hover:bg-gray-100 dark:bg-gray-900/60 dark:hover:bg-gray-800/60">
+ actions on the right. Actions are separate elements because buttons can't
+ nest. The row is a size container: the sidebar can narrow it while the
+ viewport remains desktop-sized, so action labels must respond to this
+ row's actual width rather than viewport breakpoints. Narrow rows never
+ hide an action — each one keeps its icon (with aria-label + title) and
+ only sheds its text label. */}
+ <div className="@container flex items-center gap-2 bg-gray-50 pr-2 transition-colors duration-150 hover:bg-gray-100 dark:bg-gray-900/60 dark:hover:bg-gray-800/60">
<button
type="button"
aria-expanded={open}
@@ -636,36 +640,38 @@ export function ModelsPage() {
</button>
{isOwner && (
// Add-model entry point: present on every group header (including
- // custom), new models belong to that group. The page header has no
- // global add button, so this doesn't collapse on narrow screens either.
- <span className="shrink-0">
- <Button
- size="sm"
- variant="ghost"
- disabled={busy}
- onClick={() => setAddingTo(group.provider.id)}
- >
- <GlyphIcon d={PLUS_ICON} size={13} />
- {S.models.addToGroup}
- </Button>
- </span>
+ // custom), new models belong to that group. Narrow rows never hide a
+ // group action — they drop its label and keep the icon (same pattern
+ // for every action in this row), so the button stays reachable.
+ <Button
+ size="sm"
+ variant="ghost"
+ className="shrink-0"
+ disabled={busy}
+ aria-label={`${S.models.addToGroup} ${group.provider.label}`}
+ title={S.models.addToGroup}
+ onClick={() => setAddingTo(group.provider.id)}
+ >
+ <GlyphIcon d={PLUS_ICON} size={13} />
+ <span className="hidden @3xl:inline">{S.models.addToGroup}</span>
+ </Button>
)}
{isOwner && group.provider.id !== "custom" && (
- // Not enough room on phone width for group-level actions: collapse it
- // (per-model keys can still be configured in the card dialog). Wrapped
- // in a span and hidden there: passing hidden directly to Button conflicts
- // with its inline-flex base class.
- <span className="hidden shrink-0 sm:block">
- <Button
- size="sm"
- variant="ghost"
- disabled={busy}
- onClick={() => setGroupKeyFor(group.provider.id)}
- >
- <GlyphIcon d={KEY_ICON} size={13} />
- {S.models.groupApiKey}
- </Button>
- </span>
+ // Bulk key action: icon-only while this row is narrow, labeled from
+ // @3xl up. The button itself never disappears — aria-label + title
+ // carry the name while the visible label is dropped.
+ <Button
+ size="sm"
+ variant="ghost"
+ className="shrink-0"
+ disabled={busy}
+ aria-label={`${S.models.groupApiKey} ${group.provider.label}`}
+ title={S.models.groupApiKey}
+ onClick={() => setGroupKeyFor(group.provider.id)}
+ >
+ <GlyphIcon d={KEY_ICON} size={13} />
+ <span className="hidden @3xl:inline">{S.models.groupApiKey}</span>
+ </Button>
)}
{isOwner && (
<Button
@@ -682,8 +688,8 @@ export function ModelsPage() {
onClick={() => setSpeedFor(group.provider.id)}
>
<GlyphIcon d={GAUGE_ICON} size={13} />
- {/* Phone width: icon only (the header can't fit three labeled actions at 390px). */}
- <span className="hidden sm:inline">
+ {/* Compact rows keep this accessible action icon-only. */}
+ <span className="hidden @3xl:inline">
{speedRunning === group.provider.id
? S.models.speedPending
: S.models.speedTest}
@@ -691,16 +697,19 @@ export function ModelsPage() {
</Button>
)}
{group.provider.apiKeyUrl && (
- // Not enough room on phone width for all group-level actions: collapse
- // it the same way as "bulk configure key", keeping the add entry and
- // vendor name + count from crowding each other.
+ // External link: its label is the last one admitted as space grows
+ // (@4xl); below that it collapses to the external-link glyph with a
+ // small padding bump for a usable touch target.
<a
href={group.provider.apiKeyUrl}
target="_blank"
rel="noreferrer noopener"
- className="hidden shrink-0 whitespace-nowrap text-xs text-brand-600 underline-offset-2 hover:underline sm:inline dark:text-brand-300"
+ aria-label={`${S.models.getApiKey} ${group.provider.label}`}
+ title={S.models.getApiKey}
+ className="inline-flex shrink-0 items-center whitespace-nowrap p-1 text-xs text-brand-600 underline-offset-2 hover:underline @4xl:p-0 dark:text-brand-300"
>
- {S.models.getApiKey} ↗
+ <GlyphIcon d={EXTERNAL_LINK_ICON} size={13} className="@4xl:hidden" />
+ <span className="hidden @4xl:inline">{S.models.getApiKey} ↗</span>
</a>
)}
{/* Collapse arrow sits at the far right of the header (after group actions); it too can be clicked to collapse. */}