diff --git a/webui/browser/continuity.spec.ts b/webui/browser/continuity.spec.ts index 1edddbafd..6b4da722c 100644 --- a/webui/browser/continuity.spec.ts +++ b/webui/browser/continuity.spec.ts @@ -45,6 +45,8 @@ for (const name of ["Conversation actions", "Quick note"]) { const box = (await surface.boundingBox())!; expect(box.x).toBeGreaterThanOrEqual(0); expect(box.x + box.width).toBeLessThanOrEqual(width); + // Exercise Escape after the first interactive paint, not before Radix's layer effect. + await surface.evaluate(() => new Promise(requestAnimationFrame)); if (name === "Quick note") await page.getByRole("textbox", { name: "Quick note draft" }).press("Escape"); else await surface.press("Escape"); await expect(surface).toBeHidden(); @@ -123,6 +125,7 @@ test("reduced motion keeps the same controls without travel or delayed teardown" await expect(surface).toHaveCSS("pointer-events", "auto"); if (name === "Quick note") await expect(page.getByRole("textbox", { name: "Quick note draft" })).toBeFocused(); else await expect(surface).toBeFocused(); + await surface.evaluate(() => new Promise(requestAnimationFrame)); if (name === "Quick note") await page.getByRole("textbox", { name: "Quick note draft" }).press("Escape"); else await surface.press("Escape"); await expect(surface).toBeHidden(); diff --git a/webui/browser/workspace-access-focus.spec.ts b/webui/browser/workspace-access-focus.spec.ts index c9714a354..b3255e9fd 100644 --- a/webui/browser/workspace-access-focus.spec.ts +++ b/webui/browser/workspace-access-focus.spec.ts @@ -49,7 +49,10 @@ test("keyboard selection restores visible focus to the permission trigger", asyn test("Escape restores keyboard focus even after pointer entry", async ({ page }) => { const trigger = page.locator(".thread-composer-access"); await trigger.click(); - await expect(page.getByRole("menu")).toBeVisible(); + const menu = page.getByRole("menu"); + // Reduced motion can expose the surface before Radix finishes its focus/layer setup. + await expect(menu).toBeFocused(); + await expect(menu).toHaveCSS("pointer-events", "auto"); await page.keyboard.press("Escape"); await expect(page.getByRole("menu")).toHaveCount(0); await expect(trigger).toHaveAccessibleName("Workspace access mode: Full Access"); diff --git a/webui/src/components/thread/WorkspaceControls.tsx b/webui/src/components/thread/WorkspaceControls.tsx index cf35ebf76..153f2319c 100644 --- a/webui/src/components/thread/WorkspaceControls.tsx +++ b/webui/src/components/thread/WorkspaceControls.tsx @@ -759,6 +759,8 @@ export function WorkspaceAccessMenu({ { restoreTriggerFocus.current = false; }} onKeyDownCapture={() => { restoreTriggerFocus.current = true; }} + // Radix handles Escape at the document layer, before React's content key handler. + onEscapeKeyDown={() => { restoreTriggerFocus.current = true; }} onPointerDownOutside={() => { restoreTriggerFocus.current = false; }} onCloseAutoFocus={event => { if (!restoreTriggerFocus.current) event.preventDefault(); }} className="w-max min-w-[13rem] max-w-[calc(100vw-2rem)]">