JS function with e.key === 'Enter' won't fire when in screenreader (NVDA ) browse mode

1.3k Views Asked by At

Keyboard ENTER on a button element will not fire the psydo code at the bottom, when NVDA screenreader is enabled and in browse mode. I already found some suggestion, but they do not cover my requirements:

  • Add role=application --> The content is no longer read correctly by the screenreader.
  • Switch to focus mode manual --> Yes, this works. But the button is to open a dropdown. So the user don't expect to have to switch into focus mode.

So I know that the NVDA screenreader "swallow" some of the keyboard events. But I don't know any work-around. Do you have any idea?

Thanks a lot :-)

// psuedo code

button.addEventListener('keypress', e => {
  if (e.key === 'Enter') {
    // code
  }
}
1

There are 1 best solutions below

0
On

Because screen readers like NVDA intercept / swallow some keyboard events (in browse mode), I'm using now the click event. This one gets fired even NVDA is enabled and in browse mode.

button.addEventListener('click', () => {
  // code
}