Skip to content

Fix accessibility for image block with legend #454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/js/classes/ImageBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import AbstractDomElement from './AbstractDomElement'

// ----
// class
// ----
class ImageBlock extends AbstractDomElement {
constructor(element, options) {
const instance = super(element, options)

// avoid double init :
if (!instance.isNewInstance()) {
return instance
}

const el = this._element
const figure = el.closest('.wp-block-image')

// 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
figure.setAttribute('role', 'figure')
figure.setAttribute('aria-label', el.textContent)
}
}

// ----
// init
// ----
ImageBlock.init('.wp-block-image figcaption')

// ----
// export
// ----
export default ImageBlock
1 change: 1 addition & 0 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ import './classes/ScrollDirection'
import './classes/ButtonSeoClick'
import './classes/Header'
import './classes/Animation'
import './classes/ImageBlock'
Loading