41

What is the best approach to make an SPA (AngularJS) Accessible (for screen readers etc)?

I have little to no experience with the aria specification, and I wonder if it will at all work on a single page application.

What are the common pitfalls when developing?

How do one debug and test the accessibility when developing?

Kenneth Lynne
  • 15,461
  • 12
  • 63
  • 79
  • What accessibility are you talking about? Can you be more clear... – Abilash Mar 10 '13 at 12:51
  • what does ARIA have to do with javascript or angular or single page vs multi page? – charlietfl Mar 10 '13 at 14:05
  • From what I understand it is a big differende between for example a href link and an onclick link? And if I were to use an off canvas navigation pattern, how will screen readers understand what content is in focus? Maybe I have got this whole thing wrong? – Kenneth Lynne Mar 10 '13 at 15:06
  • 2
    Perhaps: http://webaim.org/techniques/javascript/eventhandlers will help – Ryan B Mar 11 '13 at 14:45
  • 2
    @charlietfl screen readers load page content into their buffer when the page initially loads, if content is added/changed after that initial load, [aria live regions](http://juicystudio.com/article/wai-aria_live-regions_updated.php) can help ensure that dynamically loaded content is announced. – steveax Mar 11 '13 at 15:01
  • @steveax I realize the proper ARIA attributes need to be set in markup, however that is a broad topic for one question. Reality is...OP needs to study the specs and do research before posting overly broad question here – charlietfl Mar 11 '13 at 15:15

1 Answers1

74

This could cover a broad swath of issues here. So I'll go through some of the basics in the hopes that it starts you on your way, the common pitfalls, as it were.

Firstly, like the commenters said, yes, you need to make sure ARIA tags are employed correctly. So, say, if you wanted to expose a div as a button, you'd have something like this.

<div id="mysuperflashybutton" ... role="button" aria-label="Super flashy" tabindex="0"></div>

This button when selected by a screen reader will be called "super flashy button", so you don't need to put button in your aria-label attribute. There are more complex examples out there, but that illustrates the basics of it, pretty much. Role, aria-label and tabindex will be the most prevalent ARIA attributes you see.

Tab-indexing elements that you want screen reader users to click on is vital to this. Set tabindex to 0 to include it in its default location on the document. If you don't want it to necessarily normally be reached by people using keyboard navigation, set it to -1. This means it's out of the normal tab order, but can still be navigated to if you want to put the user's focus there manually through javascript/jquery .focus().

As mentioned, sometimes you can assist keyboard navigators/screen reader users by moving their focus for them. An example would be if they click a button and a menu appears. You could do something like this to put them on the first link of the menu:

$('#linkmenuactivator').on("click", function () {
    $('#linkmenu').find('li:first a').focus();
});

I know that's in JQuery, I'm not familiar with AngularJS but my brief view makes me think it's more of a ViewModel controller as opposed to something UI specific like JQuery, but correct me if I'm wrong.

Live regions can be used if you're doing funky things on screen that will make no sense to a screen reader user. You can write text to the elements in these regions to put the information out textually. The easiest way to do this is to use a role of alert or status, for important messages or generic status updates respectively. These roles make your element a live region by default, and any text changes in there will be reported to the screen reader. So a quick example would look something like this:

<p id="ariastatusbox" ... role="status"></p>

Then later in JQuery (taking the example of you loading a document and fading it in when you've got it):

$('#maincontent').fadeIn(function () {
    $('#ariastatusbox').text('Document loaded');
});

This will let the screen reader know that the document is loaded and ready to be read on screen. Live regions can be slightly tricky, but they're a powerful beasty if you can master them.

Finally, as to accessibility testing, there's a few options. Something I recently stumbled across is Wave which appears to be an online testing tool. It looks good from a first glance, you could give it a try. Another option is to grab a screen reader yourself and give it a go. I recommend NVDA which is an open-source (so therefore free) screen reader. It's my screen reader of choice and is pretty damn good. The synthesiser it comes bundled with doesn't have the nicest voice, but there are other options, or you could turn off the speech output and view a textual display of what it would be saying using the Speech Viewer. A final option is to ask for accessibility testers to take your app for a test drive. For consumer products or things in those brackets, blind people and other users of accessible tech may well volunteer to do it if asked. For more business oriented apps that you might not want out in a public forum, there are several organisations that can consult on issues of making web applications accessible.

This is by no means a comprehensive manual on accessibility, I was hoping to really kickstart you in the right direction. For a bit of a deeper look, try looking at the ARIA roles documentation (all of it will help but the code is under the definitions heading), and on from that the ARIA States and Properties documentation. They both can be a little dry, but also have the full list of everything you can use ARIA wise. Google should be able to yield some tutorials, too, I hope.

I hope this helps get you started. Good luck!

Craig Brett
  • 2,295
  • 1
  • 22
  • 27
  • Thank you very much Craig, this will help me, and probably many more to come in making our sites more accessible. This was just the kind of introduction i hoped for. – Kenneth Lynne Mar 24 '13 at 15:26
  • 1
    @Craig This is a fantastic answer, I wish I could vote it up multiple times. :-) – DSimon Mar 25 '13 at 18:22