Client side accessibility error scanner.
Перейти к файлу
Mu-An ✌️ Chiou ad08c47b3f Add how we use this script in github as an example 2017-10-12 18:34:22 +08:00
test Pass in pairs for tests 2017-10-12 18:22:11 +08:00
.babelrc Change window global 2017-10-06 10:11:27 +08:00
.eslintrc Fix eslint and point to the right main file 2017-10-06 09:51:34 +08:00
.gitignore Add babel for es2015 2017-10-06 09:30:42 +08:00
LICENSE Add license text 2017-06-26 23:42:08 +08:00
README.md Add how we use this script in github as an example 2017-10-12 18:34:22 +08:00
example.html Make ariaPairs an option to pass in 2017-10-12 18:19:49 +08:00
index.js Make ariaPairs an option to pass in 2017-10-12 18:19:49 +08:00
package-lock.json Test in headless firefox with Karma 2017-10-12 14:59:07 +08:00
package.json Test in headless firefox with Karma 2017-10-12 14:59:07 +08:00

README.md

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.

Red borders are added to offending elements example

An alert pops up on clicking the elements

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.