Skip to content

Commit a1b856b

Browse files
committed
feat: Adding the "axeRun" method to trigger manually
1 parent e401cad commit a1b856b

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

Diff for: src/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function install (Vue, options) {
88
if (typeof window === 'undefined') return
99

1010
const defaultOptions = {
11-
clearConsoleOnUpdate: true,
11+
clearConsoleOnUpdate: false,
1212
config: {
1313
checks: [{
1414
id: 'color-contrast',
@@ -43,22 +43,24 @@ export default function install (Vue, options) {
4343
updated () {
4444
this.debounceAxe()
4545
},
46-
// Used for change of route
4746
beforeDestroy () {
4847
this.clearAxeConsole(true)
4948
},
5049
methods: {
5150
clearAxeConsole (forceClear = false) {
5251
resetCache()
5352

54-
if (forceClear && options.clearConsoleOnUpdate) {
53+
if (forceClear || options.clearConsoleOnUpdate) {
5554
console.clear()
5655
resetLastNotification()
5756
}
5857
},
58+
axeRun ({ clearConsole = false, element = document } = {}) {
59+
this.clearAxeConsole(clearConsole)
60+
this.$nextTick(() => checkAndReport(options, element))
61+
},
5962
debounceAxe: debounce(function () {
60-
this.clearAxeConsole()
61-
this.$nextTick(() => checkAndReport(options, this.$el))
63+
this.axeRun()
6264
}, 1000, { maxWait: 5000 })
6365
}
6466
})

Diff for: src/utils.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import axeCore from 'axe-core'
22

33
let cache = {}
44
let style = {}
5-
const nodes = []
65
const deferred = {}
76
let lastNotification = ''
87

98
export function checkAndReport (options, node) {
10-
nodes.push(node)
119
const deferred = createDeferred()
1210
style = { ...options.style }
1311

14-
axeCore.run(document, options.runOptions, (error, results) => {
12+
axeCore.run(node || document, options.runOptions, (error, results) => {
1513
if (error) deferred.reject(error)
1614
if (!results) return
1715
if (JSON.stringify(results.violations) === lastNotification) return

0 commit comments

Comments
 (0)