Close image modals with Escape (#415)

This commit is contained in:
Gaurav Chaudhary 2026-09-07 17:04:54 +00:00 committed by hodlbod
parent 17467808ca
commit cd1fbca21d
3 changed files with 25 additions and 2 deletions

View file

@ -142,6 +142,15 @@ test("US-062 see images and video inline", async ({seed, as}) => {
await expect(lightbox).toBeVisible()
await page.keyboard.press("Escape")
await expect(page.locator(".dialog")).toHaveCount(0)
await expect(inlineImage).toBeVisible()
await inlineImage.click()
await expect(lightbox).toBeVisible()
await lightbox.click()
await expect(page.locator(".dialog")).toHaveCount(0)

View file

@ -590,6 +590,14 @@ test("US-080 preview a profile from anywhere", async ({seed, as}) => {
await expect(dialog(page).getByText("Deckhand, dockside cook")).toBeVisible()
await expect(dialog(page).getByText(/Last active/)).toBeVisible()
await page.keyboard.press("Escape")
await expect(page.locator(".dialog")).toHaveCount(0)
await expect(page).toHaveURL(new RegExp(`${spacePath(url)}/directory$`))
await expect(preview).toBeVisible()
await preview.click()
await dialog(page).getByRole("button", {name: "Go back"}).click()
// Closed, and alice is exactly where she opened it from.

View file

@ -10,8 +10,14 @@
}
}
const onKeyDown = (e: any) => {
if (e.code === "Escape" && e.target === document.body) {
const onKeyDown = (event: KeyboardEvent) => {
const target = event.target
if (
event.code === "Escape" &&
target instanceof Element &&
!target.closest("input, textarea, [contenteditable]")
) {
closeModal()
}
}