diff --git a/webui/browser/attachment-layout.spec.ts b/webui/browser/attachment-layout.spec.ts index dd1db3248..b328f8a4b 100644 --- a/webui/browser/attachment-layout.spec.ts +++ b/webui/browser/attachment-layout.spec.ts @@ -187,9 +187,17 @@ test("image lightbox and file download remain keyboard accessible", async ({ pag await page.keyboard.press("ArrowRight"); await expect(page.getByRole("dialog", { name: "Blue study.svg" })).toBeVisible(); await page.keyboard.press("End"); - await expect(page.getByRole("dialog", { name: "Green study.svg" })).toBeVisible(); + const lightbox = page.getByRole("dialog", { name: "Green study.svg" }); + await expect(lightbox).toBeVisible(); await page.screenshot({ path: testInfo.outputPath("lightbox.png") }); await testInfo.attach("image lightbox", { path: testInfo.outputPath("lightbox.png"), contentType: "image/png" }); + const viewport = lightbox.getByTestId("image-zoom-viewport"); + await viewport.click(); + await expect(viewport).toHaveCSS("box-shadow", "none"); + await page.keyboard.press("="); + await expect(lightbox.getByRole("button", { name: "Fit image" })).toHaveText("150%"); + await expect(viewport).toBeFocused(); + await expect(viewport).not.toHaveCSS("box-shadow", "none"); await page.keyboard.press("Escape"); await expect(page.getByRole("dialog")).toHaveCount(0); await expect(firstImage).toBeFocused(); diff --git a/webui/browser/inline-file-reference.spec.ts b/webui/browser/inline-file-reference.spec.ts index 52aacf51c..e944d3f62 100644 --- a/webui/browser/inline-file-reference.spec.ts +++ b/webui/browser/inline-file-reference.spec.ts @@ -49,9 +49,19 @@ test("inferred files wrap without losing copy text or preview actions", async ({ await files.nth(1).click(); await expect(page.getByLabel("Opened file")).toHaveText(`notes/${"long directory/".repeat(16)}report.md`); - await files.first().press("Enter"); + const first = files.first(); + await first.press("Enter"); await expect(page.getByLabel("Opened file")).toHaveText("notes/ready.md"); - await files.first().press("Shift+F10"); + await first.click(); + await expect(first).toHaveCSS("box-shadow", "none"); + await page.keyboard.press("Shift+F10"); + const copyMenu = page.getByRole("menu"); + await expect(copyMenu).toBeVisible(); + await page.keyboard.press("Escape"); + await expect(first).toBeFocused(); + await expect(first).not.toHaveCSS("box-shadow", "none"); + + await page.keyboard.press("Shift+F10"); await page.getByRole("menuitem", { name: "Copy absolute path", exact: true }).click(); expect(await page.evaluate(() => navigator.clipboard.readText())).toBe("notes/ready.md"); await files.nth(6).hover(); diff --git a/webui/browser/model-options.spec.ts b/webui/browser/model-options.spec.ts index 2d6aa85d7..275cec69b 100644 --- a/webui/browser/model-options.spec.ts +++ b/webui/browser/model-options.spec.ts @@ -258,7 +258,9 @@ for (const { width, height, theme } of [ test(`selects a custom preset's reasoning effort in the themed picker at ${width}px`, async ({ page }, testInfo) => { await page.setViewportSize({ width, height }); await page.goto(`/browser/fixture.html?case=model-options&group=local&${theme}`); - await page.getByRole("button", { name: "Default", exact: true }).click(); + // Loading an empty thread moves the composer into the welcome layout. + const welcome = page.getByTestId("thread-welcome-layout"); + await welcome.getByRole("button", { name: "Default", exact: true }).click(); const dialog = page.getByRole("dialog", { name: "Switch model", exact: true }); await dialog.getByRole("option", { name: "Custom API", exact: true }).click(); await page.getByRole("button", { name: "Custom API", exact: true }).click(); diff --git a/webui/src/components/FileActions.tsx b/webui/src/components/FileActions.tsx index a3040f56a..3f5347f4c 100644 --- a/webui/src/components/FileActions.tsx +++ b/webui/src/components/FileActions.tsx @@ -7,6 +7,7 @@ import { useFloatingPortal } from "@/components/ui/floating-portal"; import { useToast } from "@/components/ui/toast"; import { copyTextToClipboard } from "@/lib/clipboard"; import { useOverlaySurfaceRef } from "@/lib/dom-overlays"; +import { markKeyboardFocus } from "@/lib/focus-modality"; import type { FileReferenceMetadata, FilePreviewPayload } from "@/lib/types"; import { cn } from "@/lib/utils"; @@ -104,6 +105,7 @@ export function FileActions({ }} onKeyDown={(event) => { if (event.key === "ContextMenu" || (event.key === "F10" && event.shiftKey)) { + markKeyboardFocus(event.currentTarget.ownerDocument); event.preventDefault(); event.stopPropagation(); const bounds = event.currentTarget.getBoundingClientRect(); diff --git a/webui/src/components/ui/image-viewport.tsx b/webui/src/components/ui/image-viewport.tsx index 0d8568d0c..8b01a7950 100644 --- a/webui/src/components/ui/image-viewport.tsx +++ b/webui/src/components/ui/image-viewport.tsx @@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState, type PointerEvent } from "rea import { Minus, Plus } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { markKeyboardFocus } from "@/lib/focus-modality"; import { cn } from "@/lib/utils"; type Point = { x: number; y: number }; @@ -136,6 +137,7 @@ export function ImageViewport({ else if (panWithArrows && event.key === "ArrowUp") apply({ ...current, y: current.y + PAN_STEP }); else if (panWithArrows && event.key === "ArrowDown") apply({ ...current, y: current.y - PAN_STEP }); else return; + markKeyboardFocus(event.currentTarget.ownerDocument); event.preventDefault(); event.stopPropagation(); }}> diff --git a/webui/src/lib/focus-modality.ts b/webui/src/lib/focus-modality.ts index 3253750ba..0bbbc2f3a 100644 --- a/webui/src/lib/focus-modality.ts +++ b/webui/src/lib/focus-modality.ts @@ -50,6 +50,11 @@ interface InstalledModality { const installedDocuments = new WeakMap(); +/** Mark a keyboard action handled by a control outside the shared navigation keys. */ +export function markKeyboardFocus(doc: Document): void { + doc.documentElement.dataset.focusModality = "keyboard"; +} + /** * Track whether the user is navigating by keyboard or pointer on `html[data-focus-modality]`. * @@ -82,7 +87,7 @@ export function installFocusModality(doc: Document = document): () => void { root.dataset.focusModality = "pointer"; }; const onKeyDown = (event: KeyboardEvent) => { - if (isKeyboardFocusKey(event)) root.dataset.focusModality = "keyboard"; + if (isKeyboardFocusKey(event)) markKeyboardFocus(doc); }; doc.addEventListener("pointerdown", setPointer, { capture: true, passive: true });