MAESTRO: Improve CAPTCHA modal keyboard access

This commit is contained in:
Mariusz Banach
2026-02-18 04:29:32 +01:00
parent 39558ccb7d
commit 86a368b14d
3 changed files with 83 additions and 1 deletions

View File

@@ -194,4 +194,40 @@ describe("CaptchaChallenge", () => {
expect(onClose).toHaveBeenCalled();
});
it("keeps focus trapped within the modal when tabbing", () => {
const { container } = render(
<CaptchaChallenge
isOpen
challenge={sampleChallenge}
onVerify={vi.fn()}
onSuccess={vi.fn()}
onRetry={vi.fn()}
onClose={vi.fn()}
/>,
);
const closeButton = getByTestId(container, "captcha-close") as HTMLButtonElement;
const submit = getByTestId(container, "captcha-submit") as HTMLButtonElement;
submit.focus();
expect(document.activeElement).toBe(submit);
act(() => {
submit.dispatchEvent(new KeyboardEvent("keydown", { key: "Tab", bubbles: true }));
});
expect(document.activeElement).toBe(closeButton);
closeButton.focus();
expect(document.activeElement).toBe(closeButton);
act(() => {
closeButton.dispatchEvent(
new KeyboardEvent("keydown", { key: "Tab", shiftKey: true, bubbles: true }),
);
});
expect(document.activeElement).toBe(submit);
});
});