Make your single page apps work with screen readers

Single-page apps pose a significant accessibility challenge when it comes to communicating view changes. Without a page refresh, screen readers do not pick up these important UI changes, leaving vision-impaired users confused and unaware.

One solution is to create a message based on the page title, and leverage an ARIA live region to explicitly announce, via a helpful message, that a new view has loaded. First create a function that is called when viewContent is updated. AngularJS provides a $viewContentLoaded event for this purpose. In the controller code, listen for the event and call a function (in CoffeeScript):

app.controller 'PageController', ($scope, $location, $http) ->
$scope.$on '$viewContentLoaded', announce_view_loaded

In the announce_view_loaded function, update the page title and announce the message. While single-page frameworks do not automatically update page titles, keeping the page title synced with the current view improves users’ understanding of the view.

One way to do this is to use a data attribute somewhere in the view to store the view title:

document.title = $('[data-viewtitle]').data 'viewtitle'

Now create a message using the updated page title, and announce it:

$.announce(document.title + ', view loaded')

$.announce() is a jQuery function that uses a single, non-visible live region to announce content. This approach helps simplify the code and debugging efforts compared to the ad hoc use of live regions. However, there are a few best practices to remember.

First, create a single ‘announcer’ live region in your page to announce content using aria-live="polite|assertive". Do not use any other live regions, including live region roles (e.g. role="alert|timer|log"). An example live region:

<div aria-live="polite" id="announcer">(Text added or updated here will be announced)</div>

Second, clear the contents of the live region shortly after updating the content. This prevents users from stumbling upon old messages.

Finally, as with any accessibility technique, use $.announce() judiciously. It should only be used for communicating significant UI updates.

Words: Patrick Fox

Patrick Fox is Web UI technology director at Razorfish in Austin. This article originally appeared in issue 271 of net magazine.

Liked this? Read these!

Thank you for reading 5 articles this month* Join now for unlimited access

Enjoy your first month for just £1 / $1 / €1

*Read 5 free articles per month without a subscription

Join now for unlimited access

Try first month for just £1 / $1 / €1

The Creative Bloq team is made up of a group of design fans, and has changed and evolved since Creative Bloq began back in 2012. The current website team consists of eight full-time members of staff: Editor Georgia Coggan, Deputy Editor Rosie Hilder, Ecommerce Editor Beren Neale, Senior News Editor Daniel Piper, Editor, Digital Art and 3D Ian Dean, Tech Reviews Editor Erlingur Einarsson and Ecommerce Writer Beth Nicholls and Staff Writer Natalie Fear, as well as a roster of freelancers from around the world. The 3D World and ImagineFX magazine teams also pitch in, ensuring that content from 3D World and ImagineFX is represented on Creative Bloq.