Skip to content

Commit 30d060c

Browse files
authored
Merge pull request #21151 from calixteman/bug2034568
Fix clicking on a thumbnail image not navigating to the correct page when using a screen reader (bug 2034568)
2 parents f41c60a + b669fdf commit 30d060c

2 files changed

Lines changed: 27 additions & 6 deletions

File tree

test/integration/thumbnail_view_spec.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ describe("PDF Thumbnail View", () => {
210210
})
211211
);
212212
});
213+
214+
it("must navigate when a synthetic click is dispatched on the thumbnail image (bug 2034568)", async () => {
215+
await Promise.all(
216+
pages.map(async ([browserName, page]) => {
217+
await showViewsManager(page);
218+
await waitForThumbnailVisible(page, 3);
219+
220+
// Simulate a screen reader (e.g. NVDA) firing a synthetic click on
221+
// the <img> child rather than the thumbnailImageContainer button.
222+
await page.evaluate(() => {
223+
const img = document.querySelector(
224+
`.thumbnail[page-number="3"] .thumbnailImageContainer img`
225+
);
226+
img.dispatchEvent(new MouseEvent("click", { bubbles: true }));
227+
});
228+
229+
const currentPage = await page.$eval(
230+
"#pageNumber",
231+
el => el.valueAsNumber
232+
);
233+
expect(currentPage).withContext(`In ${browserName}`).toBe(3);
234+
})
235+
);
236+
});
213237
});
214238

215239
describe("The manage dropdown menu", () => {

web/pdf_thumbnail_viewer.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,12 +1547,9 @@ class PDFThumbnailViewer {
15471547
}
15481548

15491549
#goToPage(e) {
1550-
const { target } = e;
1551-
if (target.classList.contains("thumbnailImageContainer")) {
1552-
const pageNumber = parseInt(
1553-
target.parentElement.getAttribute("page-number"),
1554-
10
1555-
);
1550+
const container = e.target.closest(".thumbnailImageContainer");
1551+
if (container) {
1552+
const pageNumber = parseInt(container.getAttribute("page-number"), 10);
15561553
this.linkService.goToPage(pageNumber);
15571554
stopEvent(e);
15581555
}

0 commit comments

Comments
 (0)