Skip to content

Commit 2dc071b

Browse files
committed
Fix accessibility for image block with legend
1 parent 032dfa0 commit 2dc071b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/js/classes/ImageBlock.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
figure.setAttribute('role', 'group')
19+
figure.setAttribute('aria-label', el.textContent)
20+
}
21+
}
22+
23+
// ----
24+
// init
25+
// ----
26+
ImageBlock.init('.wp-block-image figcaption')
27+
28+
// ----
29+
// export
30+
// ----
31+
export default ImageBlock

src/js/index.js

Lines changed: 1 addition & 0 deletions
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)