+
hello
-
@@ -56,7 +71,7 @@ exports[`sets the status 1`] = `
aria-relevant="additions text"
style="border: 0px; height: 1px; margin: -1px; overflow: hidden; padding: 0px; position: absolute; width: 1px;"
>
-
diff --git a/src/__tests__/set-a11y-status.js b/src/__tests__/set-a11y-status.js
index 88960db5b..d01ba4d09 100644
--- a/src/__tests__/set-a11y-status.js
+++ b/src/__tests__/set-a11y-status.js
@@ -31,6 +31,12 @@ test('does add anything for an empty string', () => {
expect(document.body.innerHTML.trim()).toMatchSnapshot()
})
+test('escapes HTML', () => {
+ const setA11yStatus = setup()
+ setA11yStatus('')
+ expect(document.body.innerHTML.trim()).toMatchSnapshot()
+})
+
function setup() {
jest.resetModules()
return require('../set-a11y-status').default
diff --git a/src/set-a11y-status.js b/src/set-a11y-status.js
index f5aafd44b..14ab6f910 100644
--- a/src/set-a11y-status.js
+++ b/src/set-a11y-status.js
@@ -14,15 +14,25 @@ function setStatus(status) {
statuses = [status]
}
const div = getStatusDiv()
- div.innerHTML = `${statuses
- .filter(Boolean)
- .map(getStatusHtml)
- .join('')}`
+
+ // Remove previous children
+ while (div.lastChild) {
+ div.removeChild(div.firstChild)
+ }
+
+ statuses.filter(Boolean).forEach((statusItem, index) => {
+ div.appendChild(getStatusChildDiv(statusItem, index))
+ })
}
-function getStatusHtml(status, index) {
+function getStatusChildDiv(status, index) {
const display = index === statuses.length - 1 ? 'block' : 'none'
- return `
${status}
`
+
+ const childDiv = document.createElement('div')
+ childDiv.style.display = display
+ childDiv.textContent = status
+
+ return childDiv
}
function getStatusDiv() {