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 (opens in new tab).
Liked this? Read these!
- The designer's guide to digital accessibility
- The best free script fonts
- Free graffiti font (opens in new tab) selection