From 1aa2f0ec655aaabc2d6c4f145f79f6e0ffda51f4 Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Fri, 6 Nov 2026 19:09:21 -0500 Subject: [PATCH] Tab rows no longer scroll when every tab fits The shared tab row (components/tabs.tsx) pulled its list down 1px with a negative bottom margin so the active underline would sit on the nav's border. The list is inside an overflow-x-auto box, which makes the box scroll on both axes, so the list ended up 1px taller than the box and the box scrolled even when every tab fit, drawing a scrollbar under the tabs on desktop. The base line is now the list's own bottom border, and each tab pulls down 1px onto it inside the list's box, so nothing overflows. The list is at least as wide as its tabs, so the line runs the full scrolled width on a phone. e2e/tabs-no-scroll.spec.ts checks every page with a tab row. --- dashboard/e2e/tabs-no-scroll.spec.ts | 80 ++++++++++++++++++++++++++++ dashboard/src/components/tabs.tsx | 16 +++--- 2 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 dashboard/e2e/tabs-no-scroll.spec.ts diff --git a/dashboard/e2e/tabs-no-scroll.spec.ts b/dashboard/e2e/tabs-no-scroll.spec.ts new file mode 100644 index 00000000..12043379 --- /dev/null +++ b/dashboard/e2e/tabs-no-scroll.spec.ts @@ -0,0 +1,80 @@ +import { expect, test, type Page } from "@playwright/test"; +import { mockWideApi } from "./wide-data"; +import { SAMPLE_QUERY } from "./wide-data/addresses"; + +// A row of tabs (components/tabs.tsx) scrolls only when its tabs don't fit. +// On a desktop screen every row here fits, so its scroll box must not scroll +// either way: a box that is even 1px bigger inside than out draws a scrollbar +// under the tabs. On a phone a row may scroll inside itself, but the page +// never scrolls sideways. +// +// Every page that draws the shared tab row is listed; the spec fails if a +// listed page stops drawing one, so the list can't quietly go stale. + +const PAGES = [ + "/runs/detail", // Overview, Changes, Activity, Details + "/analytics", + "/tests", + "/admin", + "/settings/agents", + "/settings/deliveries", + "/skills/agent", + "/reviewer", // the section's pages (Reviewer, Tests, Releases) + "/logs", // the section's pages (Logs, Alerts) + "/settings/instructions", // the Instructions pages +]; + +const DESKTOP = [1280, 1600]; +const PHONE = 375; + +async function open(page: Page, path: string, width: number) { + await page.setViewportSize({ width, height: 900 }); + await page.goto(path + (SAMPLE_QUERY[path] ?? "")); + await page.waitForLoadState("networkidle", { timeout: 15_000 }).catch(() => {}); + await expect(page.getByTestId("topbar")).toBeVisible(); + await page.waitForTimeout(300); +} + +/** Each visible tab row's scroll box: its inside and outside sizes. */ +function rows(page: Page) { + return page.evaluate(() => + Array.from(document.querySelectorAll("[data-testid=tab-row] > [data-scroll-fade]")) + .filter((el) => el.getClientRects().length > 0) + .map((el) => ({ + label: el.closest("nav")?.getAttribute("aria-label") ?? "", + scrollWidth: el.scrollWidth, + clientWidth: el.clientWidth, + scrollHeight: el.scrollHeight, + clientHeight: el.clientHeight, + })), + ); +} + +test.describe.configure({ mode: "parallel" }); + +for (const path of PAGES) { + test(`tab row does not scroll when it fits: ${path}`, async ({ page }) => { + await mockWideApi(page); + const problems: string[] = []; + for (const width of DESKTOP) { + await open(page, path, width); + const found = await rows(page); + if (!found.length) problems.push(`${path} at ${width}px draws no tab row`); + for (const r of found) { + if (r.scrollWidth > r.clientWidth) problems.push(`${path} at ${width}px: "${r.label}" is ${r.scrollWidth - r.clientWidth}px wider inside than out`); + if (r.scrollHeight > r.clientHeight) problems.push(`${path} at ${width}px: "${r.label}" is ${r.scrollHeight - r.clientHeight}px taller inside than out`); + } + } + await open(page, path, PHONE); + const { scrollWidth, clientWidth } = await page.evaluate(() => ({ + scrollWidth: document.documentElement.scrollWidth, + clientWidth: document.documentElement.clientWidth, + })); + if (scrollWidth > clientWidth) problems.push(`${path} at ${PHONE}px is ${scrollWidth - clientWidth}px wider than the screen`); + // On a phone the row may scroll sideways, but never up and down. + for (const r of await rows(page)) { + if (r.scrollHeight > r.clientHeight) problems.push(`${path} at ${PHONE}px: "${r.label}" is ${r.scrollHeight - r.clientHeight}px taller inside than out`); + } + expect(problems.join("\n"), `${path}: a tab row scrolls though its tabs fit, or the page scrolls sideways`).toBe(""); + }); +} diff --git a/dashboard/src/components/tabs.tsx b/dashboard/src/components/tabs.tsx index 364d2a29..82847025 100644 --- a/dashboard/src/components/tabs.tsx +++ b/dashboard/src/components/tabs.tsx @@ -43,16 +43,20 @@ export function Tabs({ const asSelect = items.length > selectAbove; const current = items.find((t) => t.value === value); + // The base line is the row's own bottom border, and each tab's underline + // pulls down 1px to sit on it. Both stay inside the row's box: a negative + // margin on the row itself would make the scroll box 1px taller inside than + // out, so it scrolled (and showed a scrollbar) even when every tab fit. const row = ( -