|
3 | 3 | Accessibility auditing for Vue.js applications by running [dequelabs/axe-core](https://github.com/dequelabs/axe-core/) validation on the page you're viewing, `axe-core` will run 1 second after the last VueJS update (with a 5 seconds debounce max wait). Package inspired by [dequelabs/react-axe](https://github.com/dequelabs/react-axe).
|
4 | 4 |
|
5 | 5 | ## Links
|
| 6 | +- [Documentation](https://axe.vue-a11y.com) |
6 | 7 | - [Demo](https://vue-axe.surge.sh/)
|
7 | 8 |
|
8 |
| -## Install package |
9 |
| -#### NPM |
10 |
| -```shell |
11 |
| -npm install -D axe-core vue-axe |
12 |
| -``` |
13 |
| - |
14 |
| -#### Yarn |
15 |
| -```shell |
16 |
| -yarn add -D axe-core vue-axe |
17 |
| -``` |
18 |
| ---- |
19 |
| - |
20 |
| -## Install plugin |
21 |
| -```javascript |
22 |
| -import Vue from 'vue' |
23 |
| - |
24 |
| -if (process.env.NODE_ENV !== 'production') { |
25 |
| - const VueAxe = require('vue-axe').default |
26 |
| - Vue.use(VueAxe) |
27 |
| -} |
28 |
| -``` |
29 |
| -## Configuration |
30 |
| -| Key | Type | Description | Default |
31 |
| -| ---------------------- | -------- |-------------------------------------------------------------- | ----------- |
32 |
| -| `auto` | Boolean | Disables automatic verification. Only checks with `$axe.run` | `true` |
33 |
| -| `clearConsoleOnUpdate` | Boolean | Clears the console each time `vue-axe` runs | `false` |
34 |
| -| `customResultHandler` | Function | Handle the results. (This may be needed for automated tests) |
35 |
| -| `config` | Object | Provide your [Axe-core configuration](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#api-name-axeconfigure) | [See default config](https://github.com/vue-a11y/vue-axe/blob/master/src/index.js#L13) |
36 |
| -| `runOptions` | Object | Provide your [Axe-core runtime options](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#options-parameter) | [See default runOption](https://github.com/vue-a11y/vue-axe/blob/master/src/index.js#L18) |
37 |
| -| `delay` | Number | Used to delay the first check. - `Millisecond` |
38 |
| -| `style` | Object | Customize style for console logs. | [See default style](https://github.com/vue-a11y/vue-axe/blob/master/src/index.js#L22) |
39 |
| -| `plugins` | Array | Register Axe plugins. [Axe docs: Plugins](https://github.com/dequelabs/axe-core/blob/master/doc/plugins.md) |
40 |
| - |
41 |
| -### Custom Result Handler |
42 |
| - |
43 |
| -The `customResultHandler` config property expects a callback like the `axe.run()` callback ([see documentation](https://github.com/dequelabs/axe-core/blob/master/doc/API.md#parameters-axerun)). It will be triggered after each call to `axe.run()`. |
44 |
| - |
45 |
| -```javascript |
46 |
| -import Vue from 'vue' |
47 |
| - |
48 |
| -if (process.env.NODE_ENV !== 'production') { |
49 |
| - const VueAxe = require('vue-axe').default |
50 |
| - Vue.use(VueAxe, { |
51 |
| - customResultHandler: (error, results) => { |
52 |
| - results.violations.forEach(violation => console.log(violation)) |
53 |
| - } |
54 |
| - // ... |
55 |
| - }) |
56 |
| -} |
57 |
| -``` |
58 |
| - |
59 |
| -### Run axe manually |
60 |
| -The `$axe` is available on the property injected into the Vue instance, so it is available everywhere in your application. With it it is possible to execute the `$axe.run` method to check manually your document or any desired HTMLElement. |
61 |
| - |
62 |
| -#### `$axe.run({ clearConsole: Boolean, element: Document | HTMLElement })` |
63 |
| - |
64 |
| -```vue |
65 |
| -<script> |
66 |
| -//... |
67 |
| - methods: { |
68 |
| - axeRun() { |
69 |
| - this.$axe.run({ |
70 |
| - clearConsole: false, |
71 |
| - element: this.$el // e.g. document, document.querySelector('.selector'), ... |
72 |
| - }) |
73 |
| - } |
74 |
| - } |
75 |
| -</script> |
76 |
| -``` |
77 |
| - |
78 |
| -### Running custom axe plugins |
79 |
| -Learn more about [axe plugin](https://github.com/dequelabs/axe-core/blob/master/doc/plugins.md) |
80 |
| - |
81 |
| -```vue |
82 |
| -<script> |
83 |
| -//... |
84 |
| - methods: { |
85 |
| - handle () { |
86 |
| - this.$axe.plugins.myPlugin.run() |
87 |
| - } |
88 |
| - } |
89 |
| -</script> |
90 |
| -``` |
91 |
| - |
92 |
| -## Install in Nuxt.js |
93 |
| -Create plugin file `plugins/axe.js` |
94 |
| -```javascript |
95 |
| -import Vue from 'vue' |
96 |
| - |
97 |
| -if (process.env.NODE_ENV !== 'production') { |
98 |
| - const VueAxe = require('vue-axe').default |
99 |
| - Vue.use(VueAxe) |
100 |
| -} |
101 |
| - |
102 |
| -``` |
103 |
| - |
104 |
| -In config file `nuxt.config.js` |
105 |
| -```javascript |
106 |
| -... |
107 |
| -plugins: [ |
108 |
| - { src: '~/plugins/axe.js', mode: 'client' } |
109 |
| -] |
110 |
| -``` |
111 |
| - |
112 |
| -## Using with HTML files |
113 |
| -#### CDN |
114 |
| -```html |
115 |
| -<script src="https://unpkg.com/vue"></script> |
116 |
| -<script src="https://unpkg.com/axe-core"></script> |
117 |
| -<script src="https://unpkg.com/vue-axe"></script> |
118 |
| -``` |
119 |
| - |
120 |
| -```javascript |
121 |
| -Vue.use(VueAxe) |
122 |
| -``` |
123 |
| -## See demo |
124 |
| -https://vue-axe.surge.sh/ |
125 |
| - |
126 |
| -## Run the demo |
127 |
| -```shell |
128 |
| -git clone https://github.com/vue-a11y/vue-axe.git vue-axe |
129 |
| -cd vue-axe/demo |
130 |
| -npm install |
131 |
| -npm run dev |
132 |
| -``` |
133 |
| - |
134 |
| -It is a simple webpack template already installed and configured to run and check the logs in the browser console. |
135 |
| -After the commands just access the http://localhost:8080/ |
136 |
| - |
137 |
| - |
138 |
| -## Run the tests |
139 |
| -```shell |
140 |
| -git clone https://github.com/vue-a11y/vue-axe.git vue-axe |
141 |
| -cd vue-axe |
142 |
| -npm install |
143 |
| -npm run test |
144 |
| -``` |
145 |
| - |
146 |
| -Or run Cypress on interactive mode |
147 |
| -```shell |
148 |
| -npm run test:open |
149 |
| -``` |
150 |
| - |
151 | 9 | ## Contributing
|
152 | 10 | - From typos in documentation to coding new features;
|
153 | 11 | - Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found;
|
|
0 commit comments