Are there any constraints regarding accessibility testing?

posted on

Back to overview

Yes.

Debugging with accessibility testing tools

Not all accessibility testing tools support Shadow DOM. For example, Wave flags zero errors, but there are at least three in the following component.

class SomeBugs extends HTMLElement {
  constructor() {
    super();
    this.attachShadow({mode: 'open'});

    this.shadowRoot.innerHTML = `   
    <img src="#test">

    <button></button>
    <button aria-hidden="true">Click</button>
      `
  }
}

customElements.define('some-bugs', SomeBugs);
Image with no alt, empty button, and aria-hidden interactive element.
Browser version of wave showing 0 errors

Debugging with DevTools

I like to use the live expression feature in Chrome's Dev Tools to debug keyboard accessibility issues by logging document.activeElement.

When I focus a button in light DOM, it returns the focused button.

Focus on button 1. Dev tools logs button.button1

When I focus a button in shadow DOM, it returns the parent component.

Focus on button 2. Dev tools logs cus-tom12

To workaround that I have to create a second live expression that logs document.activeElement.shadowRoot.activeElement.

Focus on button 2. Dev tools logs cus-tom12 and button.button2

That's okay, but you get an annoying error when focusing an element without a shadow root.

Focus on button 1. Dev tools logs button.button1 and Uncaught TypeError: Cannot read properties of null…

Back to overview