Skip to content

Commit 18bafeb

Browse files
committed
Add some aria-labels to the paste button in order to know where the buttons are (bug 2020758)
1 parent 68cca32 commit 18bafeb

3 files changed

Lines changed: 59 additions & 2 deletions

File tree

l10n/en-US/viewer.ftl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,4 +767,9 @@ pdfjs-views-manager-status-undo-button-label = Undo
767767
pdfjs-views-manager-status-close-button =
768768
.title = Close
769769
pdfjs-views-manager-status-close-button-label = Close
770-
pdfjs-views-manager-paste-button-label = Paste
770+
771+
# Variables:
772+
# $page (Number) - the page number after which the paste button is.
773+
pdfjs-views-manager-paste-button-after-label = Paste after page { $page }
774+
775+
pdfjs-views-manager-paste-button-before-label = Paste before the first page

test/integration/reorganize_pages_spec.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ import {
2020
createPromise,
2121
createPromiseWithArgs,
2222
dragAndDrop,
23+
FSI,
2324
getAnnotationSelector,
2425
getRect,
2526
getThumbnailSelector,
2627
kbCopy,
2728
kbCut,
2829
kbDelete,
2930
loadAndWait,
31+
PDI,
3032
scrollIntoView,
3133
showViewsManager,
3234
waitAndClick,
@@ -792,6 +794,42 @@ describe("Reorganize Pages View", () => {
792794
await closePages(pages);
793795
});
794796

797+
it("should check that the paste button spans have the right l10n id depending on their position", async () => {
798+
await Promise.all(
799+
pages.map(async ([browserName, page]) => {
800+
await waitForThumbnailVisible(page, 1);
801+
await page.waitForSelector("#viewsManagerStatusActionButton", {
802+
visible: true,
803+
});
804+
await waitAndClick(
805+
page,
806+
`.thumbnail:has(${getThumbnailSelector(1)}) input`
807+
);
808+
809+
const handlePagesEdited = await waitForPagesEdited(page);
810+
await waitAndClick(page, "#viewsManagerStatusActionButton");
811+
await waitAndClick(page, "#viewsManagerStatusActionCopy");
812+
await awaitPromise(handlePagesEdited);
813+
814+
const prevSpanText = await page.$eval(
815+
`button.thumbnailPasteButton:has(+ ${getThumbnailSelector(1)}) > span`,
816+
el => el.textContent.trim()
817+
);
818+
expect(prevSpanText)
819+
.withContext(`In ${browserName}`)
820+
.toBe("Paste before the first page");
821+
822+
const afterSpanText = await page.$eval(
823+
`${getThumbnailSelector(1)} + button.thumbnailPasteButton > span`,
824+
el => el.textContent.trim()
825+
);
826+
expect(afterSpanText)
827+
.withContext(`In ${browserName}`)
828+
.toBe(`Paste after page ${FSI}1${PDI}`);
829+
})
830+
);
831+
});
832+
795833
it("should check that a page can be copied and pasted before the first thumbnail", async () => {
796834
await Promise.all(
797835
pages.map(async ([browserName, page]) => {

web/pdf_thumbnail_view.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,28 @@ class PDFThumbnailView extends RenderableView {
183183
pasteButton.classList.add("thumbnailPasteButton", "viewsManagerButton");
184184
pasteButton.tabIndex = 0;
185185
const span = document.createElement("span");
186-
span.setAttribute("data-l10n-id", "pdfjs-views-manager-paste-button-label");
186+
span.setAttribute(
187+
"data-l10n-id",
188+
"pdfjs-views-manager-paste-button-after-label"
189+
);
190+
span.setAttribute(
191+
"data-l10n-args",
192+
JSON.stringify({
193+
page: this.pageLabel ?? this.id,
194+
})
195+
);
187196
pasteButton.append(span);
188197
pasteButton.addEventListener("click", () => {
189198
pasteCallback(this.id);
190199
});
191200
if (this.id === 1) {
192201
const prevPasteButton = (this.prevPasteButton =
193202
pasteButton.cloneNode(true));
203+
const prevSpan = prevPasteButton.firstElementChild;
204+
prevSpan.setAttribute(
205+
"data-l10n-id",
206+
"pdfjs-views-manager-paste-button-before-label"
207+
);
194208
prevPasteButton.addEventListener("click", () => {
195209
pasteCallback(0);
196210
});

0 commit comments

Comments
 (0)