Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
fix(ui): portal the docs Export menu so the header doesn't clip it (#3778)
Yunus Ozenb20e291e5a90
diff --git a/packages/ui/__tests__/docs/export-menu.test.tsx b/packages/ui/__tests__/docs/export-menu.test.tsxnew file mode 100644index 000000000..2cc680829--- /dev/null+++ b/packages/ui/__tests__/docs/export-menu.test.tsx@@ -0,0 +1,65 @@+/**+ * The docs header scrolls its actions horizontally, so a menu positioned inside+ * it is clipped and its items can't be clicked (#3678). The Export menu is+ * portalled out of the header instead.+ */+import { describe, it, expect, vi } from "vitest";+import { render, screen, fireEvent } from "@testing-library/react";+import { ExportMenu } from "../../src/docs/docs-page-actions.js";++function renderInScrollingHeader(+ props: Partial<Parameters<typeof ExportMenu>[0]> = {},+) {+ const handlers = { onExportPage: vi.fn(), onExportAll: vi.fn() };+ render(+ <div+ data-testid="header-actions"+ className="ml-auto flex min-w-0 items-center gap-2 overflow-x-auto"+ >+ <ExportMenu+ isExporting={false}+ zipHref="/export.zip"+ hasPage+ {...handlers}+ {...props}+ />+ </div>,+ );+ fireEvent.click(screen.getByRole("button", { name: /export/i }));+ return handlers;+}++describe("ExportMenu", () => {+ it("renders its items outside the scrolling header", () => {+ renderInScrollingHeader();++ const items = screen.getAllByRole("menuitem");+ expect(items.map((item) => item.textContent)).toEqual([+ "This page (Markdown)",+ "All pages (Markdown)",+ "ZIP archive",+ ]);+ const header = screen.getByTestId("header-actions");+ for (const item of items) expect(header.contains(item)).toBe(false);+ });++ it("runs the chosen export and closes", () => {+ const { onExportAll } = renderInScrollingHeader();++ fireEvent.click(+ screen.getByRole("menuitem", { name: "All pages (Markdown)" }),+ );++ expect(onExportAll).toHaveBeenCalledTimes(1);+ expect(screen.queryByRole("menuitem")).toBeNull();+ });++ it("leaves out the page export when there is no page", () => {+ renderInScrollingHeader({ hasPage: false });++ expect(+ screen.queryByRole("menuitem", { name: "This page (Markdown)" }),+ ).toBeNull();+ expect(screen.getAllByRole("menuitem")).toHaveLength(2);+ });+});diff --git a/packages/ui/src/docs/docs-page-actions.tsx b/packages/ui/src/docs/docs-page-actions.tsxindex d3e2d5ca6..b31f51f8c 100644--- a/packages/ui/src/docs/docs-page-actions.tsx+++ b/packages/ui/src/docs/docs-page-actions.tsx@@ -11,6 +11,7 @@ import {} from "lucide-react";import { Spinner } from "../ui/spinner";import { Button } from "../ui/button";+import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover";import { ConfidenceBadge } from "../wiki/confidence-badge";import { READER_PERSONAS, type ReaderPersona } from "./reader-persona";import { cn } from "../lib/cn";@@ -114,71 +115,66 @@ export function ExportMenu({const itemClass ="flex w-full items-center gap-2 rounded px-2 py-1.5 text-xs text-[var(--color-text-secondary)] transition-colors hover:bg-[var(--color-bg-elevated)] hover:text-[var(--color-text-primary)]";+ // The menu is portalled: the docs header scrolls its actions horizontally, and+ // an absolutely positioned menu inside that scroll container gets clipped.return (- <div className="relative">- <Button- variant="outline"- size="sm"- onClick={() => setOpen((o) => !o)}- disabled={isExporting}- aria-haspopup="menu"- aria-expanded={open}- >- {isExporting ? (- <Spinner size="sm" className="mr-1.5" />- ) : (- <Download className="h-3.5 w-3.5 mr-1.5" />- )}- Export- <ChevronDown className="h-3 w-3 ml-1 opacity-60" />- </Button>- {open && (- <>- <div className="fixed inset-0 z-10" onClick={() => setOpen(false)} />- <div- role="menu"- className="absolute right-0 top-full z-20 mt-1 w-52 rounded-md border border-[var(--color-border-default)] bg-[var(--color-bg-surface)] p-1 shadow-md"- >- {hasPage && (- <>- <button- role="menuitem"- className={itemClass}- onClick={() => {- setOpen(false);- onExportPage();- }}- >- <Download className="h-3.5 w-3.5 shrink-0" />- This page (Markdown)- </button>- <div className="my-1 border-t border-[var(--color-border-default)]" />- </>- )}+ <Popover open={open} onOpenChange={setOpen}>+ <PopoverTrigger asChild>+ <Button+ variant="outline"+ size="sm"+ disabled={isExporting}+ aria-haspopup="menu"+ aria-expanded={open}+ >+ {isExporting ? (+ <Spinner size="sm" className="mr-1.5" />+ ) : (+ <Download className="h-3.5 w-3.5 mr-1.5" />+ )}+ Export+ <ChevronDown className="h-3 w-3 ml-1 opacity-60" />+ </Button>+ </PopoverTrigger>+ <PopoverContent role="menu" align="end" className="w-52 p-1">+ {hasPage && (+ <><buttonrole="menuitem"className={itemClass}onClick={() => {setOpen(false);- onExportAll();+ onExportPage();}}>- <FileText className="h-3.5 w-3.5 shrink-0" />- All pages (Markdown)+ <Download className="h-3.5 w-3.5 shrink-0" />+ This page (Markdown)</button>- <a- role="menuitem"- href={zipHref}- download- className={itemClass}- onClick={() => setOpen(false)}- >- <FolderArchive className="h-3.5 w-3.5 shrink-0" />- ZIP archive- </a>- </div>- </>- )}- </div>+ <div className="my-1 border-t border-[var(--color-border-default)]" />+ </>+ )}+ <button+ role="menuitem"+ className={itemClass}+ onClick={() => {+ setOpen(false);+ onExportAll();+ }}+ >+ <FileText className="h-3.5 w-3.5 shrink-0" />+ All pages (Markdown)+ </button>+ <a+ role="menuitem"+ href={zipHref}+ download+ className={itemClass}+ onClick={() => setOpen(false)}+ >+ <FolderArchive className="h-3.5 w-3.5 shrink-0" />+ ZIP archive+ </a>+ </PopoverContent>+ </Popover>);}