3

The react example below only exhibits the unexpected behavior on Firefox with VoiceOver.

Using the aria-live attribute on this p tag, I expect my screen reader to read me the text when it is updated. However, my screen reader is not reading me the updated text. The screen reader I'm using is VoiceOver on a macbook.

I have created the same little app with html and vanilla JS, and it works as expected . code and codepen link are below...

If you're on a mac and you've never done it before, hold command and press touchID 3 times to start VoiceOver.

Here is my react code... Link to codepen

// jsx
const App = () => {
  const [text, setText] = React.useState('hello')
  const handleClick = () => {
    if(text === 'hello') {
      setText('goodbye')
    } else {
      setText('hello')
    }
  }
  
  return (
    <div>
      <p aria-live="polite">{text}</p>
      <button
        type="button"
        onClick={handleClick}
      >
        click
      </button>
    </div>
  )
}

ReactDOM.render(<App />,
document.getElementById("root"))
<!-- html -->
<div id="root"></div>

...and here is my behaving-as-expected html/vanilla JS code... Link to codepen

<!-- html -->
<div>
  <p aria-live="polite" id="text">hello</p>
  <button
    type="button"
    id="btn"
  >
    click here
  </button>
</div>
<script>
  const text = document.getElementById('text');
  const btn = document.getElementById('btn');

  function handleClick() {
    if (text.innerText === 'hello') {
      text.innerText = 'goodbye';
    } else {
      text.innerText = 'hello';
    }
  }

  btn.addEventListener('click', handleClick);
</script>
Jake Loew
  • 81
  • 7
  • So you just want to change the `aria-live` attribute by state? Then add another `const [ariaLive, setAriaLive] = useState("polite")` which you can change depending on your logic and add it with `

    `.. or do I get you wrong?
    – PRSHL Aug 23 '21 at 19:54
  • Does your vanilla JS version work on Firefox? Seems like Firefox maybe just doesn't fully support `aria-live`. https://caniuse.com/?search=aria-live – cjl750 Aug 23 '21 at 20:13
  • 1
    @PRSHL Incorrect. I'm not changing the value of `aria-live`. @cjl750 Yes the vanilla JS does work in Firefox, but I suspect you're right that this has something to do with Firefox + React + VoiceOver not playing nicely. – Jake Loew Aug 26 '21 at 15:00
  • Did you ever resolve this? – coppereyecat Aug 29 '22 at 20:39
  • @coppereyecat somewhat, see my comment above. – Jake Loew Aug 31 '22 at 22:12
  • We were having a similar issue but as it turns out, `role="alert"` doesn't work on spans (and neither did any of the other aria live stuff). setting it to a div instead ended up resolving our issue. – coppereyecat Sep 01 '22 at 15:03

0 Answers0