Skip to content

Commit 21f8b98

Browse files
authored
Merge pull request #454 from BeAPI/fix-image-block
Fix accessibility for image block with legend
2 parents 9f7af67 + 2eafbb4 commit 21f8b98

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/js/classes/ImageBlock.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import AbstractDomElement from './AbstractDomElement'
2+
3+
// ----
4+
// class
5+
// ----
6+
class ImageBlock extends AbstractDomElement {
7+
constructor(element, options) {
8+
const instance = super(element, options)
9+
10+
// avoid double init :
11+
if (!instance.isNewInstance()) {
12+
return instance
13+
}
14+
15+
const el = this._element
16+
const figure = el.closest('.wp-block-image')
17+
18+
// Add role="figure" and aria-label with the figure text to comply with RGAA criteria 1.9.1 : https://accessibilite.numerique.gouv.fr/methode/criteres-et-tests/#1.9
19+
figure.setAttribute('role', 'figure')
20+
figure.setAttribute('aria-label', el.textContent)
21+
}
22+
}
23+
24+
// ----
25+
// init
26+
// ----
27+
ImageBlock.init('.wp-block-image figcaption')
28+
29+
// ----
30+
// export
31+
// ----
32+
export default ImageBlock

src/js/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import './classes/ScrollDirection'
44
import './classes/ButtonSeoClick'
55
import './classes/Header'
66
import './classes/Animation'
7+
import './classes/ImageBlock'

0 commit comments

Comments
 (0)