admin管理员组文章数量:1022467
When you dynamically add an element to an aria-live region, Chrome will read out all the items in that region which is great.
But when you remove an element, Chrome does not re-read out the list. This is an issue when you're using the region for errors and such, as when the user has fixed an error, the list is not re-read out.
Example here:
<div aria-live='assertive'>
</div>
<button id='add'>add</button>
<button id='remove'>remove</button>
const addBtn = document.querySelector('#add')
const removeBtn = document.querySelector('#remove')
const ariaLive = document.querySelector('div')
let tick = 0
addBtn.addEventListener('click', () => {
let newElem = document.createElement('span')
newElem.textContent = tick
tick++
console.log(ariaLive, newElem)
ariaLive.appendChild(newElem)
})
removeBtn.addEventListener('click', () => {
ariaLive.removeChild(ariaLive.lastChild)
})
When you dynamically add an element to an aria-live region, Chrome will read out all the items in that region which is great.
But when you remove an element, Chrome does not re-read out the list. This is an issue when you're using the region for errors and such, as when the user has fixed an error, the list is not re-read out.
Example here: https://codepen.io/mildrenben/pen/WNNzVzN?editors=1010
<div aria-live='assertive'>
</div>
<button id='add'>add</button>
<button id='remove'>remove</button>
const addBtn = document.querySelector('#add')
const removeBtn = document.querySelector('#remove')
const ariaLive = document.querySelector('div')
let tick = 0
addBtn.addEventListener('click', () => {
let newElem = document.createElement('span')
newElem.textContent = tick
tick++
console.log(ariaLive, newElem)
ariaLive.appendChild(newElem)
})
removeBtn.addEventListener('click', () => {
ariaLive.removeChild(ariaLive.lastChild)
})
Share
Improve this question
asked Nov 6, 2019 at 16:39
mildrenbenmildrenben
3,7576 gold badges27 silver badges37 bronze badges
3
- 1 Are you talking about Chrome Vox? You didn't specify the actual screen reader causing issues. – GrahamTheDev Commented Nov 6, 2019 at 17:47
- Sorry, I'm referring to MacOS built in VoiceOver. – mildrenben Commented Nov 7, 2019 at 10:44
- Ahh, I don't have access to anything Apple at the moment but I know from experience VoiceOver doesn't always play well with Chrome. I think that use case is entirely small as most VoiceOver users tend to stick with Safari or Firefox (at least that's what our user feedback tends to say) because of the issues. Unless someone says otherwise I would think it is a bug as your code looks fine, wish I had something handy I could test it on for you. – GrahamTheDev Commented Nov 7, 2019 at 16:05
2 Answers
Reset to default 2The correct method should be to use the aria-relevant
attribute, however the browser support is very poor, and as such it is not reliable.
I don't normally advocate for doing hacky things to make a browser behave a certain way, but if you really need to make the live region report removals, here's what I would suggest:
- Set the
aria-atomic
attribute on your live region totrue
. This means that the screen reader will read the entire contents of the live region each time content is added (but not removed). - When you delete an element from the live region, add another invisible element, wait a few hundred milliseconds, and then delete that element.
- The live region should announce all of the contents (minus the deletion) when the remove button is pressed.
Example fiddle here: https://jsfiddle/mug6vonf/3/
You should also use aria-relevant :
Values:
A space-delimited list of one or more of the following values:
additions
are insertion of nodes into the live region; should be considered relevant.removals
are deletion of nodes; should be considered relevant.text
are changes to the textual content of existing nodes; should be considered relevant.all
is equivalent to additions removals text.
aria-relevant="additions text"
is the default value on a live region.
The default value doesn't include removals
, which you probably need.
When you dynamically add an element to an aria-live region, Chrome will read out all the items in that region which is great.
But when you remove an element, Chrome does not re-read out the list. This is an issue when you're using the region for errors and such, as when the user has fixed an error, the list is not re-read out.
Example here:
<div aria-live='assertive'>
</div>
<button id='add'>add</button>
<button id='remove'>remove</button>
const addBtn = document.querySelector('#add')
const removeBtn = document.querySelector('#remove')
const ariaLive = document.querySelector('div')
let tick = 0
addBtn.addEventListener('click', () => {
let newElem = document.createElement('span')
newElem.textContent = tick
tick++
console.log(ariaLive, newElem)
ariaLive.appendChild(newElem)
})
removeBtn.addEventListener('click', () => {
ariaLive.removeChild(ariaLive.lastChild)
})
When you dynamically add an element to an aria-live region, Chrome will read out all the items in that region which is great.
But when you remove an element, Chrome does not re-read out the list. This is an issue when you're using the region for errors and such, as when the user has fixed an error, the list is not re-read out.
Example here: https://codepen.io/mildrenben/pen/WNNzVzN?editors=1010
<div aria-live='assertive'>
</div>
<button id='add'>add</button>
<button id='remove'>remove</button>
const addBtn = document.querySelector('#add')
const removeBtn = document.querySelector('#remove')
const ariaLive = document.querySelector('div')
let tick = 0
addBtn.addEventListener('click', () => {
let newElem = document.createElement('span')
newElem.textContent = tick
tick++
console.log(ariaLive, newElem)
ariaLive.appendChild(newElem)
})
removeBtn.addEventListener('click', () => {
ariaLive.removeChild(ariaLive.lastChild)
})
Share
Improve this question
asked Nov 6, 2019 at 16:39
mildrenbenmildrenben
3,7576 gold badges27 silver badges37 bronze badges
3
- 1 Are you talking about Chrome Vox? You didn't specify the actual screen reader causing issues. – GrahamTheDev Commented Nov 6, 2019 at 17:47
- Sorry, I'm referring to MacOS built in VoiceOver. – mildrenben Commented Nov 7, 2019 at 10:44
- Ahh, I don't have access to anything Apple at the moment but I know from experience VoiceOver doesn't always play well with Chrome. I think that use case is entirely small as most VoiceOver users tend to stick with Safari or Firefox (at least that's what our user feedback tends to say) because of the issues. Unless someone says otherwise I would think it is a bug as your code looks fine, wish I had something handy I could test it on for you. – GrahamTheDev Commented Nov 7, 2019 at 16:05
2 Answers
Reset to default 2The correct method should be to use the aria-relevant
attribute, however the browser support is very poor, and as such it is not reliable.
I don't normally advocate for doing hacky things to make a browser behave a certain way, but if you really need to make the live region report removals, here's what I would suggest:
- Set the
aria-atomic
attribute on your live region totrue
. This means that the screen reader will read the entire contents of the live region each time content is added (but not removed). - When you delete an element from the live region, add another invisible element, wait a few hundred milliseconds, and then delete that element.
- The live region should announce all of the contents (minus the deletion) when the remove button is pressed.
Example fiddle here: https://jsfiddle/mug6vonf/3/
You should also use aria-relevant :
Values:
A space-delimited list of one or more of the following values:
additions
are insertion of nodes into the live region; should be considered relevant.removals
are deletion of nodes; should be considered relevant.text
are changes to the textual content of existing nodes; should be considered relevant.all
is equivalent to additions removals text.
aria-relevant="additions text"
is the default value on a live region.
The default value doesn't include removals
, which you probably need.
版权声明:本文标题:javascript - Aria-live region is not reading out updates when an element is removed on chrome - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745573924a2156904.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论