2017-11-14 11:35:33 +03:00
# accessibilityjs ![build status](https://travis-ci.org/github/accessibilityjs.svg?branch=master)
2017-09-28 10:28:16 +03:00
Client side accessibility error scanner.
2017-10-13 10:00:46 +03:00
## Install
```
2017-10-13 13:37:25 +03:00
npm install accessibilityjs --save
2017-10-13 10:00:46 +03:00
```
2017-09-28 10:28:16 +03:00
## Usage
```javascript
2017-10-12 18:37:41 +03:00
import {scanForProblems} from 'accessibilityjs'
2017-09-28 10:28:16 +03:00
2017-10-12 12:26:27 +03:00
function logError(error) {
2017-10-13 06:46:59 +03:00
error.element.classList.add('accessibility-error')
2017-09-28 10:28:16 +03:00
error.element.addEventListener('click', function () {
alert(`${error.name}\n\n${error.message}`)
}, {once: true})
}
2017-10-19 16:21:10 +03:00
document.addEventListener('DOMContentLoaded', function() {
2017-09-28 10:28:16 +03:00
scanForProblems(document, logError)
})
```
2017-10-12 12:27:32 +03:00
List of errors:
- `ImageWithoutAltAttributeError`
- `ElementWithoutLabelError`
- `LinkWithoutLabelOrRoleError`
2017-10-13 07:24:28 +03:00
- `LabelMissingControlError`
- `InputMissingLabelError`
2017-10-12 12:27:32 +03:00
- `ButtonWithoutLabelError`
- `ARIAAttributeMissingError`
2017-10-12 13:34:22 +03:00
## 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 ](https://user-images.githubusercontent.com/1153134/31491689-bb8d8068-af0d-11e7-862b-01b059e13ba1.png )
![An alert pops up on clicking the elements ](https://user-images.githubusercontent.com/1153134/31491972-c8547512-af0e-11e7-9d0d-db116eb7cf58.png )
2017-09-28 10:28:16 +03:00
## Browser support
- Chrome
- Firefox
2017-09-28 10:56:08 +03:00
- Safari 6+
- Internet Explorer 9+
2017-09-28 10:28:16 +03:00
- Microsoft Edge
Internet Explorer and Edge require a polyfill for [`closest` ](https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill ).
## Development
2017-10-21 10:39:26 +03:00
```bash
> npm install
> npm test
> npm run example
```