Taking the Axe to inaccessibility

stories_of_ren

⚡️Ren⚡️

Posted on December 11, 2020

Taking the Axe to inaccessibility

Let's talk accessibility!

When you are developing apps for everyone it's great to have some cool tools in your belt. One of these tools is React Axe as brought you from Deque.

There are of couple ways you can use Axe. The first being an extension for dev tools Extensions.

google's Developer's Tools extension

Firefox Developer's Tools Add-on

To access Axe through the extension simply open your developer's tools and click the axe tab, then you can inspect your page.

Axe in Chrome's dev tools

Another way is to wrap your app in the Axe wrapper, and you do this by first installing @axe-core/react:

npm i axe-core/react --save-dev
Enter fullscreen mode Exit fullscreen mode

or whatever you use to install

At this point, you head to the file your ReactDom.render set up, this is usually the index.{js,jsx,tsx}.

Once you've made it there it is a fairly straightforward setup to get it working.

First, you'll want to set it up so that the wrapper does not render in production, that would just be awkward like leaving random console.logs everywhere that say 'hi!'.

if (process.env.NODE_ENV !== 'production') {
// Not For Production
ReactDOM.render(app, document.getElementById('root'));
} else{
// For Production
ReactDOM.render(app, document.getElementById('root'));
}
Enter fullscreen mode Exit fullscreen mode

Now, that we have that set up we can conditionally import our module.

if (process.env.NODE_ENV !== 'production') {
// Not For Production
 import('@axe-core/react').then(axe => {
        axe.default(React, ReactDOM, 1000);
        ReactDOM.render(app, document.getElementById('root'));
    });
} else{
// For Production
ReactDOM.render(app, document.getElementById('root'));
}
Enter fullscreen mode Exit fullscreen mode

We can start up our project and open up our developer's tools and go to the console.

react-axe wrapper outputs

Axe wrapper output at moderate

These Axe wrapper outputs should help in concurrent development, as well as open up conversions with your design team to discuss color contrast issues or other conversations about accessibility.

💖 💪 🙅 🚩
stories_of_ren
⚡️Ren⚡️

Posted on December 11, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Taking the Axe to inaccessibility
react Taking the Axe to inaccessibility

December 11, 2020