Reputation: 51
i want to create a little chat application. I also want to use the screenreader to read the text to me. ( Continously updates should be read ).
So: It should be really easy by using the role "log".
<div id="canvas">
<div id="messages" role="log">
<ul id="test">
<li>Row 1</li>
<li>Row 2</li>
</ul>
</div>
</div>
But in my specical case I need to clear the parent div and creae the following content of it.
document.getElementById("canvas").innerHtml = "";
I noticed that if I fill the list again, that the screanreader will read all items again. But I will that the screenreader remebers the last state.
So I thought to cache the container like
let cache = document.getElementById("messages")
document.getElementById("canvas").innerHtml = "";
document.getElementById("canvas").append(cache);
But this also overwrite the state. I am using iOS VoiceOver. Is there a way to reach my special case? Or does someone has any ideas? Or is the only way to make sure that the parent will not be cleared?
Thank you a lot
Upvotes: 0
Views: 453
Reputation: 14772
That's simple: if you don't want existing content to be repeated, you shouldn't touch it. Append the new content instead.
If your framework replaces too many (useless) things, your framework is doing bad, or it has to be improved.
The screen reader basically monitors changes occurring in the DOM tree, in the regions it has been told to look at (the so called ARIA live regions). This is how it works in most, if not all, screen readers, browsers and OS.
Therefore, if you remove everything from one element and add it again, even it the actual text content hasn't changed, it will be read again.
Look at the screen reader point of view: in fact, it isn't desirable to make a precise analysis of what has been changed exactly in place, as you describe.
For example, Google Chrome Windows had that kind of problem in the past: if you wrote "It was cool" and than replaced by "It was cold", there were a tendency to have only "ld" read, which, of course, doesn't make sense as such. The precise analysis was probably made by the browser before communicating to the screen reader, and not in the screen reader, because it worked fine in other browsers.
But think deeper: what should be read in such a case ? Only the new word "cold" ? The entire sentence ? The paragraph ? The whole element ? Even if it's several paragraphs long ? If the content is exactly the same, has the text to be repeated, or nothing should be spoken at all, as if nothing happened ?
The answers depends a lot on the context and the screen reader can't decide to take a constant behavior once for all. So, it's simpler to just follows what happens in the DOM, and hope that the designer will update only what makes sense at the right time.
In theory, it's supposed to work like as follows, but there are still several screen readers that don't totally respect these two attributes correctly.
Note in particular that a replacement is nothing else than a removal followed by an addition, and hence, it doesn't help to solve your problem.
Upvotes: 2