Skip to content

Commit fc2ce10

Browse files
fix(a11y): add accessible page overlay labels with keyboard placement hint
Add getPageAriaLabel callback prop to PDFElements which generates context-aware aria-labels for each page overlay. Labels vary by: - single vs multi-document envelope (includes doc name and number) - adding mode vs read-only (includes 'Press Enter or Space' hint) Unit tests cover all four combinations. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 0b0b0fb commit fc2ce10

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

src/components/PdfEditor/PdfEditor.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:init-files="files"
99
:init-file-names="fileNames"
1010
:page-count-format="t('libresign', '{currentPage} of {totalPages}')"
11+
:page-aria-label="getPageAriaLabel"
1112
:auto-fit-zoom="true"
1213
:read-only="readOnly"
1314
:emit-object-click="true"
@@ -130,6 +131,23 @@ export default {
130131
},
131132
methods: {
132133
t,
134+
getPageAriaLabel({ docIndex, docName, totalDocs, pageNumber, totalPages, isAddingMode }) {
135+
const docNumber = docIndex + 1
136+
if (totalDocs > 1 && isAddingMode) {
137+
// TRANSLATORS Accessible label for a PDF page overlay when placing a signature in a multi-document envelope. {docNumber} is the current document number, {totalDocs} is the total number of documents, {docName} is the document file name, {pageNumber} is the current page, {totalPages} is the total pages.
138+
return t('libresign', 'Document {docNumber} of {totalDocs} ({docName}), page {pageNumber} of {totalPages}. Press Enter or Space to place the signature here.', { docNumber, totalDocs, docName, pageNumber, totalPages })
139+
}
140+
if (totalDocs > 1) {
141+
// TRANSLATORS Accessible label for a PDF page in a multi-document envelope (read-only mode). {docNumber} is the current document number, {totalDocs} is the total number of documents, {docName} is the document file name, {pageNumber} is the current page, {totalPages} is the total pages.
142+
return t('libresign', 'Document {docNumber} of {totalDocs} ({docName}), page {pageNumber} of {totalPages}.', { docNumber, totalDocs, docName, pageNumber, totalPages })
143+
}
144+
if (isAddingMode) {
145+
// TRANSLATORS Accessible label for a PDF page overlay when placing a signature in a single document. {pageNumber} is the current page, {totalPages} is the total number of pages.
146+
return t('libresign', 'Page {pageNumber} of {totalPages}. Press Enter or Space to place the signature here.', { pageNumber, totalPages })
147+
}
148+
// TRANSLATORS Accessible label for a PDF page in a single document (read-only mode). {pageNumber} is the current page, {totalPages} is the total number of pages.
149+
return t('libresign', 'Page {pageNumber} of {totalPages}.', { pageNumber, totalPages })
150+
},
133151
endInit(event) {
134152
this.$nextTick(async () => {
135153
const shouldAutoFit = this.$refs.pdfElements?.autoFitZoom

src/tests/components/PdfEditor/PdfEditor.spec.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,60 @@ describe('PdfEditor Component - Business Rules', () => {
836836
})
837837
})
838838

839+
describe('RULE: getPageAriaLabel accessibility labels', () => {
840+
it('single doc, not adding mode: returns plain page label', () => {
841+
const label = wrapper.vm.getPageAriaLabel({
842+
docIndex: 0,
843+
docName: 'contract.pdf',
844+
totalDocs: 1,
845+
pageNumber: 2,
846+
totalPages: 5,
847+
isAddingMode: false,
848+
})
849+
850+
expect(label).toBe('Page 2 of 5.')
851+
})
852+
853+
it('single doc, adding mode: includes keyboard placement hint', () => {
854+
const label = wrapper.vm.getPageAriaLabel({
855+
docIndex: 0,
856+
docName: 'contract.pdf',
857+
totalDocs: 1,
858+
pageNumber: 3,
859+
totalPages: 5,
860+
isAddingMode: true,
861+
})
862+
863+
expect(label).toBe('Page 3 of 5. Press Enter or Space to place the signature here.')
864+
})
865+
866+
it('multi-doc, not adding mode: includes document context', () => {
867+
const label = wrapper.vm.getPageAriaLabel({
868+
docIndex: 1,
869+
docName: 'annex.pdf',
870+
totalDocs: 3,
871+
pageNumber: 1,
872+
totalPages: 4,
873+
isAddingMode: false,
874+
})
875+
876+
expect(label).toBe('Document 2 of 3 (annex.pdf), page 1 of 4.')
877+
})
878+
879+
it('multi-doc, adding mode: includes document context and keyboard placement hint', () => {
880+
const label = wrapper.vm.getPageAriaLabel({
881+
docIndex: 0,
882+
docName: 'main.pdf',
883+
totalDocs: 2,
884+
pageNumber: 1,
885+
totalPages: 10,
886+
isAddingMode: true,
887+
})
888+
889+
expect(label).toBe('Document 1 of 2 (main.pdf), page 1 of 10. Press Enter or Space to place the signature here.')
890+
})
891+
})
892+
839893
describe('RULE: coordinate system conversion', () => {
840894
beforeEach(() => {
841895
Object.assign(wrapper.vm.$refs.pdfElements, {

0 commit comments

Comments
 (0)