Skip to content

Commit b775c5c

Browse files
committed
✨(frontend) fix rgaa 1.9.1: convert to figure/figcaption structure if caption exists
ensure semantic html structure by using figure/figcaption when captions are present Signed-off-by: Cyril <[email protected]>
1 parent 3607faa commit b775c5c

File tree

2 files changed

+59
-6
lines changed

2 files changed

+59
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
All notable changes to this project will be documented in this file.
32

43
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0),
@@ -17,6 +16,7 @@ and this project adheres to
1716
- ♿ add document visible in list and openable via enter key #1365
1817
- ♿ add pdf outline property to enable bookmarks display #1368
1918
- ♿ hide decorative icons from assistive tech with aria-hidden #1404
19+
- ♿ fix rgaa 1.9.1: convert to figure/figcaption structure #1426
2020
- ♿ remove redundant aria-label to avoid over-accessibility #1420
2121

2222
### Fixed
@@ -32,7 +32,6 @@ and this project adheres to
3232
- ♿(frontend) improve accessibility:
3333
- ♿improve NVDA navigation in DocShareModal #1396
3434

35-
3635
## [3.7.0] - 2025-09-12
3736

3837
### Added

src/frontend/apps/impress/src/features/docs/doc-editor/components/custom-blocks/AccessibleImageBlock.tsx

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,64 @@ export const accessibleImageRender = (
2525
const dom = imageRenderComputed.dom;
2626
const imgSelector = dom.querySelector('img');
2727

28-
imgSelector?.setAttribute('alt', '');
29-
imgSelector?.setAttribute('role', 'presentation');
30-
imgSelector?.setAttribute('aria-hidden', 'true');
31-
imgSelector?.setAttribute('tabindex', '-1');
28+
// Set accessibility attributes for the image
29+
if (block.props.caption) {
30+
// If there's a caption, make the image accessible with the caption as alt text
31+
imgSelector?.setAttribute('alt', block.props.caption);
32+
imgSelector?.removeAttribute('aria-hidden');
33+
imgSelector?.setAttribute('tabindex', '0');
34+
} else {
35+
// If no caption, keep image decorative
36+
imgSelector?.setAttribute('alt', '');
37+
imgSelector?.setAttribute('role', 'presentation');
38+
imgSelector?.setAttribute('aria-hidden', 'true');
39+
imgSelector?.setAttribute('tabindex', '-1');
40+
}
41+
42+
// Fix RGAA 1.9.1: Convert to figure/figcaption structure if caption exists
43+
if (block.props.caption) {
44+
const captionElement = dom.querySelector('.bn-file-caption');
45+
46+
if (captionElement) {
47+
const figureElement = document.createElement('figure');
48+
49+
// Copy all attributes from the original div
50+
figureElement.className = dom.className;
51+
const styleAttr = dom.getAttribute('style');
52+
if (styleAttr) {
53+
figureElement.setAttribute('style', styleAttr);
54+
}
55+
56+
Array.from(dom.children).forEach((child) => {
57+
figureElement.appendChild(child.cloneNode(true));
58+
});
59+
60+
// Replace the <p> caption with <figcaption>
61+
const figcaptionElement = document.createElement('figcaption');
62+
const originalCaption = figureElement.querySelector('.bn-file-caption');
63+
if (originalCaption) {
64+
figcaptionElement.className = originalCaption.className;
65+
figcaptionElement.textContent = originalCaption.textContent;
66+
originalCaption.parentNode?.replaceChild(
67+
figcaptionElement,
68+
originalCaption,
69+
);
70+
71+
// Add explicit role and aria-label for better screen reader support
72+
figureElement.setAttribute('role', 'img');
73+
figureElement.setAttribute(
74+
'aria-label',
75+
`Image: ${figcaptionElement.textContent}`,
76+
);
77+
}
78+
79+
// Return the figure element as the new dom
80+
return {
81+
...imageRenderComputed,
82+
dom: figureElement,
83+
};
84+
}
85+
}
3286

3387
return {
3488
...imageRenderComputed,

0 commit comments

Comments
 (0)