Bug: Root event delegation causes accessibiliy issues

1
closed
DarioR01
DarioR01
Posted 3 months ago

Bug: Root event delegation causes accessibiliy issues #23170

React version: 17.0.2

Steps To Reproduce

  1. Use NVDA in Firefox to Navigate through the first code example provided below. (use down arrow keystrokes to navigate the page)
  2. Notice how the graphic elements get announced as clickable.

Link to code example:

<!DOCTYPE html>
<html lang='en'>

<head>
    <title>Basic HTML5 document</title>
    <meta charset='utf-8'>
</head>

<body>
    <div id="root">
            <img src="https://picsum.photos/200/300" alt="test text"/>
    </div>

    <script>
        // event delegation
        document.querySelector('#root').addEventListener('click', () => { console.log('click') })
    </script>
</body>

</html>

From the above minimal example, you can see how events delegated to the root cause NVDA to announce the element as clickable.

If we take this other example:

<!DOCTYPE html>
<html lang='en'>

<head>
    <title>Basic HTML5 document</title>
    <meta charset='utf-8'>
</head>

<body>
    <div id="root">
            <img src="https://picsum.photos/200/300" alt="test text"/>
    </div>

    <script>
        // event delegation
        document.addEventListener('click', () => { console.log('click') })
    </script>
</body>

</html>

The element will not be read as clickable.

Putting handlers on the root is a loss of semantics, and causes the intention of handlers to be no longer communicated well to the assistive technology.

The current behaviour

NVDA reads clickable due to event delegation performed at the root level.

The expected behaviour

NVDA should not read clickable. Could react provide a way for authors to arbitrarily delegate events to the document node?