Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying root selector/element for initial report. Fix #36 #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion demo/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
Expand Down
4 changes: 3 additions & 1 deletion demo/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import App from './App.vue'
import router from './router'

// Use this plugin only development => if (process.env.NODE_ENV === 'development')
Vue.use(VueAxe)
Vue.use(VueAxe, {
element: '#app'
})
Vue.config.productionTip = false

new Vue({
Expand Down
3 changes: 2 additions & 1 deletion demo/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ export default {

handleManualButton () {
this.$axe.run({
clearConsole: true
clearConsole: true,
element: document
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ To execute the `$axe.run` method to check manually your document or any desired
| Key | Type | Default
| ------------- | ------------------------ | ----------------------------------
| clearConsole | Boolean | The same as `clearConsoleOnUpdate`
| element | Document or HTMLElement | `document`
| element | Document or HTMLElement | `element` from [options](/guide/options.html#element) or `document`
| label | Strong | `Run manually`

```js
Expand Down
18 changes: 18 additions & 0 deletions docs/guide/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,24 @@ Learn more about [Axe-core runtime options](https://github.com/dequelabs/axe-cor

Used only to delay the first check.

## element

| Type | Default |
| -------- | -------- |
| String | `null` |

A [CSS selector](https://github.com/dequelabs/axe-core/blob/develop/doc/developer-guide.md#supported-css-selectors) that selects the default portion of the document to be analyzed. Once it's set up, it's used with manually checks using [$axe.run](/guide/api.html#run).

```js
Vue.use(VueAxe, {
element: '#app'
})
```

::: tip
Even the CSS selector accepts `Document` or `HTMLElement` objects; if the `querySelector` is used before the page loads, an empty object may be registered, causing undesired behaviour
:::

## style

| Type |
Expand Down
2 changes: 1 addition & 1 deletion src/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function checkAndReport (options, node, label) {
const deferred = createDeferred()
style = { ...options.style }

axeCore.run(node || document, options.runOptions, (error, results) => {
axeCore.run(node || options.element || document, options.runOptions, (error, results) => {
if (error) deferred.reject(error)
if (results && !results.violations.length) return
if (JSON.stringify(results.violations) === lastNotification) return
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ export default function install (Vue, options = {}) {
})

// First check
setTimeout(() => draf(() => checkAndReport(options, document, 'App')), options.delay)
setTimeout(() => draf(() => checkAndReport(options, null, 'App')), options.delay)
}
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const defaultOptions = {
allowConsoleClears: true,
clearConsoleOnUpdate: false,
delay: 500,
element: null,
config: {
branding: {
application: 'vue-axe'
Expand Down