Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions apps/web/e2e/help-tip.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { expect, test } from "@playwright/test";

import { expectManagementBoundary, openConsole, writes } from "./console";

test.afterEach(async ({ request }) => expectManagementBoundary(request));

for (const activation of ["keyboard", "pinned", "hover"] as const) {
test(`Escape dismisses ${activation} help before closing an edited node`, async ({ page, request }) => {
await openConsole(page, request, "nodes?id=node-local");
const open = page.getByRole("button", { name: "Edit node", exact: true });
await open.click();
const edit = page.getByRole("dialog", { name: "Edit node" });
const name = edit.getByLabel("Name", { exact: true });
await name.fill("Unsubmitted node name");

const help = edit.getByRole("button", { name: "Help", exact: true });
if (activation === "keyboard") await page.keyboard.press("Tab");
else if (activation === "hover") await help.hover();
else await help.click();
const focused = activation === "hover" ? name : help;
await expect(focused).toBeFocused();
await expect(page.locator(".help-tip-popover")).toBeVisible();

await page.keyboard.press("Escape");
await expect(page.locator(".help-tip-popover")).toHaveCount(0);
await expect(edit).toBeVisible();
await expect(name).toHaveValue("Unsubmitted node name");
await expect(focused).toBeFocused();
await expect(help).toHaveAttribute("aria-expanded", "false");

await page.keyboard.press("Escape");
await expect(edit).toBeHidden();
await expect(open).toBeFocused();
expect(await writes(request)).toEqual([]);
});
}
9 changes: 8 additions & 1 deletion apps/web/src/components/console-ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ export function HelpTip({ children, label, id: fixedId }: { children: ReactNode;
useEffect(() => {
if (!position) return;
const close = () => hide();
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key !== "Escape") return;
event.stopPropagation();
hide();
};
// A hovered tip can be open while focus remains in a dialog's input.
document.addEventListener("keydown", handleKeyDown, true);
window.addEventListener("scroll", close, true);
window.addEventListener("resize", close);
return () => {
document.removeEventListener("keydown", handleKeyDown, true);
window.removeEventListener("scroll", close, true);
window.removeEventListener("resize", close);
};
Expand All @@ -63,7 +71,6 @@ export function HelpTip({ children, label, id: fixedId }: { children: ReactNode;
onFocus={show}
onBlur={hide}
onClick={() => { if (position && pinned) hide(); else { show(); setPinned(true); } }}
onKeyDown={(event) => { if (event.key === "Escape") hide(); }}
>
<CircleHelp size={13} strokeWidth={1.75} aria-hidden="true" />
</button>
Expand Down