From 7ae7043a90d00af7b39b89714cbcbfddf14aadc1 Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Fri, 27 Nov 2026 10:37:13 +0000 Subject: [PATCH] fix(web): a wrong file password keeps focus in the password field --- .../files/AttachmentFilePreview.office.browser.test.tsx | 1 + apps/web/src/components/files/FilePasswordPrompt.tsx | 1 + apps/web/src/components/files/PdfViewer.browser.test.tsx | 3 +++ 3 files changed, 5 insertions(+) diff --git a/apps/web/src/components/files/AttachmentFilePreview.office.browser.test.tsx b/apps/web/src/components/files/AttachmentFilePreview.office.browser.test.tsx index ccb61f86871d9..b1aeb00a1d904 100644 --- a/apps/web/src/components/files/AttachmentFilePreview.office.browser.test.tsx +++ b/apps/web/src/components/files/AttachmentFilePreview.office.browser.test.tsx @@ -1125,6 +1125,7 @@ it.each([ await password.fill("wrong"); await screen.getByRole("button", { name: "Unlock" }).click(); await expect.element(screen.getByText("Incorrect password. Try again.")).toBeVisible(); + await expect.element(password).toHaveFocus(); await password.fill("open me"); await screen.getByRole("button", { name: "Unlock" }).click(); if (kind === "docx") await expect.element(screen.getByText(content)).toBeVisible(); diff --git a/apps/web/src/components/files/FilePasswordPrompt.tsx b/apps/web/src/components/files/FilePasswordPrompt.tsx index c2f7267126e97..cbe09060794ce 100644 --- a/apps/web/src/components/files/FilePasswordPrompt.tsx +++ b/apps/web/src/components/files/FilePasswordPrompt.tsx @@ -35,6 +35,7 @@ export function FilePasswordPrompt(props: { aria-label={gt("File password")} aria-describedby={status} autoComplete="off" + autoFocus={props.incorrect} required /> diff --git a/apps/web/src/components/files/PdfViewer.browser.test.tsx b/apps/web/src/components/files/PdfViewer.browser.test.tsx index ce04a100d8d8f..b1c28756617d2 100644 --- a/apps/web/src/components/files/PdfViewer.browser.test.tsx +++ b/apps/web/src/components/files/PdfViewer.browser.test.tsx @@ -388,9 +388,12 @@ it("retries an incorrect password and renders the encrypted PDF", async () => { container.style.cssText = "display:flex;width:500px;height:400px"; await using screen = await render(, { container }); const password = screen.getByLabelText("File password"); + await expect.element(password).toBeVisible(); + await expect.element(password).not.toHaveFocus(); await password.fill("wrong"); await screen.getByRole("button", { name: "Unlock" }).click(); await expect.element(screen.getByText("Incorrect password. Try again.")).toBeVisible(); + await expect.element(password).toHaveFocus(); await password.fill("open me"); await userEvent.keyboard("{Enter}"); await expect.element(screen.getByText("Unlocked PDF")).toBeVisible();