I have chat application written in react. So when user receives a message from chatbot the screen reader should automatically read out the message when component is rendered and only if the message is equal to some specific text.
Here is the current code I have.
import React, { Component } from 'react';
class SomeComponent extends Component {
render() {
const { text } = this.props;
return (
<div>
<div aria-live={text === 'some text' ? 'polite' : 'off'}>
{text}
</div>
</div>
);
}
}
export default SomeComponent;
I tried using the aria-live but it didn’t work.
I am using NVDA as screen reader.
2
Answers
For dynamic content update,
aria-relevant
has to be used witharia-live
There are a couple things that might be happening. First, some context about ARIA live regions.
aria-live="off"
is to disable announcements for elements with an implicit live region role (such asrole="alert"
), not toggle announcements on and off''
and then to your messageGiven that, a some thoughts about your issue.
aria-live="polite"
without toggling the value, and only update the content when it needs to be announced?