Skip to content

Commit 0894bcd

Browse files
committed
✨(docs) add title metadata to exported docx/pdf for accessibility
ensures document title is preserved in exports to meet accessibility needs Signed-off-by: Cyril <c.gromoff@gmail.com>
1 parent 75da342 commit 0894bcd

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ and this project adheres to
1313
- ♿(frontend) improve accessibility:
1414
- #1354
1515
- ♿ improve accessibility by adding landmark roles to layout #1394
16-
- add document visible in list and openable via enter key #1365
16+
- add document visible in list and openable via enter key #1365
1717
- ♿ add pdf outline property to enable bookmarks display #1368
1818

1919
### Fixed
@@ -28,6 +28,8 @@ and this project adheres to
2828
### Added
2929

3030
- ✨(api) add API route to fetch document content #1206
31+
- ♿(frontend) improve accessibility:
32+
- #1349
3133

3234
### Changed
3335

src/frontend/apps/e2e/__tests__/app-impress/doc-export.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ test.describe('Doc Export', () => {
9393

9494
expect(pdfData.numpages).toBe(2);
9595
expect(pdfData.text).toContain('\n\nHello\n\nWorld'); // This is the doc text
96+
expect(pdfData.info.Title).toBe(randomDoc);
9697
});
9798

9899
test('it exports the doc to docx', async ({ page, browserName }) => {

src/frontend/apps/impress/src/features/docs/doc-export/components/ModalExport.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
7676

7777
setIsExporting(true);
7878

79-
const title = (doc.title || untitledDocument)
79+
const filename = (doc.title || untitledDocument)
8080
.toLowerCase()
8181
.normalize('NFD')
8282
.replace(/[\u0300-\u036f]/g, '')
8383
.replace(/\s/g, '-');
8484

85+
const documentTitle = doc.title || untitledDocument;
86+
8587
const html = templateSelected;
8688
let exportDocument = editor.document;
8789
if (html) {
@@ -98,10 +100,11 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
98100
exportDocument,
99101
)) as React.ReactElement<DocumentProps>;
100102

101-
// Inject language for screen reader support and enable outlines (bookmarks)
103+
// Add language, title and outline properties to improve PDF accessibility and navigation
102104
const pdfDocument = isValidElement(rawPdfDocument)
103105
? cloneElement(rawPdfDocument, {
104106
language: i18next.language,
107+
title: documentTitle,
105108
pageMode: 'useOutlines',
106109
})
107110
: rawPdfDocument;
@@ -112,10 +115,13 @@ export const ModalExport = ({ onClose, doc }: ModalExportProps) => {
112115
resolveFileUrl: async (url) => exportCorsResolveFileUrl(doc.id, url),
113116
});
114117

115-
blobExport = await exporter.toBlob(exportDocument);
118+
blobExport = await exporter.toBlob(exportDocument, {
119+
documentOptions: { title: documentTitle },
120+
sectionOptions: {},
121+
});
116122
}
117123

118-
downloadFile(blobExport, `${title}.${format}`);
124+
downloadFile(blobExport, `${filename}.${format}`);
119125

120126
toast(
121127
t('Your {{format}} was downloaded succesfully', {

0 commit comments

Comments
 (0)