Skip to content

Commit

Permalink
chore(set-a11y-status): use debounce for a11y message cleanup (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
silviuaavram authored Aug 13, 2019
1 parent 931d876 commit 10394a8
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/set-a11y-status.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {debounce} from './utils'

// istanbul ignore next
let statusDiv =
typeof document === 'undefined'
? null
: document.getElementById('a11y-status-message')

let cleanupTimerID
const cleanupStatus = debounce(() => {
getStatusDiv().textContent = ''
}, 500)

/**
* @param {String} status the status message
Expand All @@ -14,17 +18,9 @@ function setStatus(status) {
if (!status) {
return
}
if (cleanupTimerID) {
clearTimeout(cleanupTimerID)
cleanupTimerID = null
}

div.textContent = status

cleanupTimerID = setTimeout(() => {
div.textContent = ''
cleanupTimerID = null
}, 500)
cleanupStatus()
}

/**
Expand Down

0 comments on commit 10394a8

Please sign in to comment.