fix(webui): restore permission focus before immediate Escape teardown

This commit is contained in:
Xubin Ren committed 2026-11-07 23:19:32 +08:00
1 parent 9c583d7924
commit 9673c1ea8f
3 files changed
+9 -1

No files matched your search

+3
View File
@@ -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();
+4 -1
View File
@@ -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");
@@ -759,6 +759,8 @@ export function WorkspaceAccessMenu({
<DropdownMenuContent side="top" align="start" sideOffset={8} aria-label={t("thread.composer.workspace.accessAria")}
onPointerDownCapture={() => { 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)]">