1.4 KiB
1.4 KiB
accessibilityjs
Client side accessibility error scanner.
Usage
import scanForProblems from 'accessibilityjs'
function logError(error) {
error.element.addEventListener('click', function () {
alert(`${error.name}\n\n${error.message}`)
}, {once: true})
if (onPageWarning) error.element.classList.add('accessibility-error')
}
document.addEventListener('ready', function() {
scanForProblems(document, logError)
})
List of errors:
ImageWithoutAltAttributeError
ElementWithoutLabelError
LinkWithoutLabelOrRoleError
LabelMissingControl
ButtonWithoutLabelError
ARIAAttributeMissingError
Scenario
In GitHub we use this script to scan for inaccessible elements in development and production staff mode. We style the elements with red borders in the logError
function passed in, and add a click handler explaining the reasons.
Browser support
- Chrome
- Firefox
- Safari 6+
- Internet Explorer 9+
- Microsoft Edge
Internet Explorer and Edge require a polyfill for closest
.
Development
Test script changes with test.html
.