|
1 | 1 | # netlify-plugin-a11y
|
2 | 2 |
|
3 |
| -Run your critical pages through [pa11y](https://github.com/pa11y/pa11y) and fail build if accessibility failures are found. |
| 3 | +Check for accessibility issues on critical pages of your Netlify website. |
4 | 4 |
|
5 |
| -## Demo |
6 |
| - |
7 |
| -The demo site is a Gatsby blog that has been modified to have some inaccessible elements: https://netlify-plugin-a11y.netlify.com/ |
| 5 | +## What does this plugin do? |
| 6 | +This plugin uses The [`pa11y`](https://github.com/pa11y/pa11y) (which in turn uses [`axe-core`](https://github.com/dequelabs/axe-core)) to check your Netlify project for accessibility issues. |
8 | 7 |
|
9 |
| -- the [Hello World](https://netlify-plugin-a11y.netlify.com/hello-world/) page has an image with no `alt` text |
10 |
| -- the [Second Post](https://netlify-plugin-a11y.netlify.com/my-second-post/) page has a form with no submit button, and an input with no label. |
11 |
| - |
12 |
| -You can see the impact of the plugin in the deploy logs of this demo site: https://app.netlify.com/sites/netlify-plugin-a11y/deploys. By default, the plugin is set to error on failure: |
| 8 | +If issues are found, the plugin generates a report which provides: |
| 9 | +- the page on which the issue was found |
| 10 | +- a description of the issue with a link to the relevant [Deque University rule](https://dequeuniversity.com/rules/axe/latest) |
| 11 | +- the name of the error within the aXe API |
| 12 | +- the path to the the relevant DOM element |
| 13 | +- the DOM element itself |
| 14 | +- the total number of issues on the page |
| 15 | +- the sum of *all* issues across *all* pages that were checked |
13 | 16 |
|
| 17 | +By default, the plugin checks **all** your site's pages for violations of WCAG 2.1 level AA, and fail the site build if any a11y issues are found. |
| 18 | +## Demo |
14 | 19 |
|
15 |
| - |
| 20 | +The demo site is an Eleventy blog containing some pages that have accessibility issues: https://netlify-plugin-a11y-demo.netlify.com/ |
| 21 | + |
| 22 | +- the "go home" link on [the 404 page](https://netlify-plugin-a11y-demo.netlify.app/404.html) has insufficient color contrast. |
| 23 | +- the cat photo on [the blog post](https://netlify-plugin-a11y-demo.netlify.app/404.html) doesn't have an `alt` attribute. |
| 24 | +- the textarea on [the contact page](https://netlify-plugin-a11y-demo.netlify.app/contact-me/) is missing a proper label |
| 25 | + |
| 26 | + |
| 27 | +This is a screenshot of the build log for the demo site: |
| 28 | + |
| 29 | +<details> |
| 30 | + <summary>Text from screnshot of demo site build log</summary> |
| 31 | + |
| 32 | +``` bash |
| 33 | + Results for URL: file:///opt/build/repo/demo/404.html |
| 34 | +1:28:11 PM: • Error: ARIA hidden element must not contain focusable elements (https://dequeuniversity.com/rules/axe/4.3/aria-hidden-focus?application=axeAPI) |
| 35 | +1:28:11 PM: ├── aria-hidden-focus |
| 36 | +1:28:11 PM: ├── #content-not-found. > a |
| 37 | +1:28:11 PM: └── <a class="direct-link" href="#content-not-found." aria-hidden="true">#</a> |
| 38 | +1:28:11 PM: • Error: Elements must have sufficient color contrast (https://dequeuniversity.com/rules/axe/4.3/color-contrast?application=axeAPI) |
| 39 | +1:28:11 PM: ├── color-contrast |
| 40 | +1:28:11 PM: ├── html > body > main > p > a |
| 41 | +1:28:11 PM: Creating deploy upload records |
| 42 | +1:28:11 PM: └── <a href="/" style="color:#aaa">home</a> |
| 43 | +1:28:11 PM: 2 Errors |
| 44 | +1:28:11 PM: Results for URL: file:///opt/build/repo/demo/posts/2018-05-01/index.html |
| 45 | +1:28:11 PM: • Error: Images must have alternate text (https://dequeuniversity.com/rules/axe/4.3/image-alt?application=axeAPI) |
| 46 | +1:28:11 PM: ├── image-alt |
| 47 | +1:28:11 PM: ├── html > body > main > div:nth-child(2) > figure > img |
| 48 | +1:28:11 PM: └── <img src="/img/cats-570x720.png" width="570" height="720"> |
| 49 | +1:28:11 PM: 1 Errors |
| 50 | +1:28:11 PM: Results for URL: file:///opt/build/repo/demo/contact-me/index.html |
| 51 | +1:28:11 PM: • Error: Form elements must have labels (https://dequeuniversity.com/rules/axe/4.3/label?application=axeAPI) |
| 52 | +1:28:11 PM: ├── label |
| 53 | +1:28:11 PM: ├── html > body > main > div:nth-child(2) > form > textarea |
| 54 | +1:28:11 PM: └── <textarea height="auto" rows="10" width="100%" style="width: 100%"></textarea> |
| 55 | +1:28:11 PM: Starting post processing |
| 56 | +1:28:11 PM: 1 Errors |
| 57 | +1:28:11 PM: 4 accessibility violations found! Check the logs above for more information |
| 58 | +``` |
| 59 | +</details> |
16 | 60 |
|
17 | 61 |
|
18 |
| -But if that is too drastic, you can switch to `resultMode = "warn"` so that builds don't fail: |
| 62 | +## Installation via the Netlify UI |
| 63 | +To install the plugin in the Netlify UI, use this [direct in-app installation link](https://app.netlify.com/plugins/netlify-plugin-a11y/install) or go to the [plugins directory](https://app.netlify.com/plugins). |
19 | 64 |
|
20 |
| - |
| 65 | +When installed this way, the plugin follows its default behavior, which is to check **all** your site's pages for violations of WCAG 2.1 level AA, and fail the site build if any a11y issues are found. |
21 | 66 |
|
| 67 | +To change the plugin's behavior, you'll want to install it throigh your `netlify.toml` file. |
22 | 68 |
|
23 |
| -## Usage |
| 69 | +## Installation via the `netlify.toml` file |
| 70 | +First, you must be insalled as a dev dependency. If you're using NPM to manage your packages, run the following: |
| 71 | +``` bash |
| 72 | +npm install --save-dev @netlify/plugin-a11y |
| 73 | +``` |
24 | 74 |
|
25 |
| -To install the plugin in the Netlify UI, use this [direct in-app installation link](https://app.netlify.com/plugins/netlify-plugin-a11y/install) or go to the [Plugins directory](https://app.netlify.com/plugins). |
| 75 | +If you're using Yarn, run the following: |
| 76 | +``` bash |
| 77 | +yarn add --dev @netlify/plugin-a11y |
| 78 | +``` |
26 | 79 |
|
27 |
| -For file-based installation, add the following lines to your `netlify.toml` file: |
| 80 | +Next, you'll need to add the `@netlify/plugin-a11y` to the plugins section of your `netlify.toml` file. |
28 | 81 |
|
29 | 82 | ```toml
|
30 | 83 | [[plugins]]
|
31 |
| -package = "netlify-plugin-a11y" |
32 |
| - |
33 |
| - # all inputs are optional, we just show you the defaults below |
34 |
| - [plugins.inputs] |
35 |
| - |
36 |
| - # required config |
37 |
| - checkPaths = ['/'] # you can give an array of directories or paths to html files, that you want to run a11y checks on |
38 |
| - |
39 |
| - ## Another checkPaths Example |
40 |
| - checkPaths = [ |
41 |
| - '/blog', |
42 |
| - '/about.html', |
43 |
| - '/super/specific/route/index.html', |
44 |
| - ] |
45 |
| - |
46 |
| - # # optional config |
47 |
| - # ignoreDirectories = ['/admin'] # explicitly ignore these directories |
48 |
| - |
49 |
| - # resultMode = "warn" # is "error" by default |
50 |
| - |
51 |
| - # # Developer only |
52 |
| - # debugMode = true # extra logging for plugin developers |
53 |
| -``` |
54 |
| - |
55 |
| -To complete file-based installation, from your project's base directory, use npm, yarn, or any other Node.js package manager to add the plugin to `devDependencies` in `package.json`. |
56 |
| - |
57 |
| -```bash |
58 |
| -npm install -D netlify-plugin-a11y |
| 84 | + package = "@netlify/plugin-a11y" |
59 | 85 | ```
|
| 86 | +⚠️ In `.toml` files, whitespace is important! Make sure `package` is indented two spaces. |
60 | 87 |
|
61 |
| -### Execution in Netlify |
| 88 | +If you want to use the plugin's default settings (check **all** pages of your site for violations of WCAG 2.1 level AA; fail the netlify build if issues are found), this is all you need to do. If you want to change the way the plugin behaves, read on to the next section. |
62 | 89 |
|
63 |
| -Once installed and configured, the plugin will automatically run in the Netlify CI during its specified Netlify Build lifecycle event. |
| 90 | +## Configuration |
| 91 | +If you've installed the plugin via `netlify.toml`, you can add a `[[plugins.inputs]]` field to change how the plugin behaves. This table outlines the inputs the plugin accepts. All of them are optional. |
64 | 92 |
|
65 |
| -### Executing locally |
66 | 93 |
|
67 |
| -To test the execution of the Netlify Build lifecycle locally, first ensure that netlify-build is installed: |
| 94 | +| Input name | Description | Possible values | Default value | |
| 95 | +|--------------------- |------------------------------------------------------------------------------ |----------------------------------------------- |--------------- | |
| 96 | +| `checkPaths` | An array of strings indicating which pages of your site to check. | Any directories or html files in your project | `['/']` | |
| 97 | +| `failWithIssues` | A boolean indicating whether the build should fail if a11y issues are found. | `true` or `false` | `true` | |
| 98 | +| `ignoreDirectories` | An array of directories that *should not* be checked for a11y issues. | Any directories within your project | `[]` | |
| 99 | +| `standard` | The WCAG standard level against which pages are checked. | `'WCAGA'` or `'WCAGAA'` or `'WCAGAAA'` | `'WCAGAA'` | |
68 | 100 |
|
69 |
| -```bash |
70 |
| -# Ensure that you have the netlify build command available |
71 |
| -# (in future this will be provided via the CLI) |
72 |
| -npm install @netlify/build -g |
| 101 | +Here's how these inputs can be used in `netlify.toml`, with comments to explain how each input affects the plugin's behavior: |
73 | 102 |
|
74 |
| -# In the project working directory, run the build as netlify would with the build bot |
75 |
| -netlify-build |
| 103 | +``` toml |
| 104 | +[[plugins]] |
| 105 | + package = "@netlify/plugin-a11y" |
| 106 | + [plugins.inputs] |
| 107 | + # Check all HTML files in this project (the default behavior) |
| 108 | + checkPaths = ['/'] |
| 109 | + # Do not fail the build if a11y issues are found |
| 110 | + failWithIssues = false |
| 111 | + # Ignore all HTML files in `/admin` |
| 112 | + ignoreDirectories = ['/admin'] |
| 113 | + # Perform a11y check against WCAG 2.1 AAA |
| 114 | + standard = 'WCAGAAA' |
76 | 115 | ```
|
77 |
| - |
78 |
| -## Future plans |
79 |
| - |
80 |
| -- configure specific a11y rules to run |
|
0 commit comments