31

Where we stand

We are under a push for web accessibility in order to conform to certain laws governing public/educational institutions. Until now we've been getting by just making sure:

  1. our layouts were logically ordered ;
  2. images had alt="" tags. but are quickly learning that we need to get in gear and really think about this.

What we are considering

We've been looking at AngularJS as a framework for dynamic web applications, but are concerned about what it may mean for our accessibility standing.

I understand that a browser with no JavaScript will likely break a highly dynamic Angular app (e.g. expressions such as {{ item.something }} embedded in the markup, using ng-repeat to build lists from a single <li>, client-side partial views as empty tags, etc.).

Question

I'm wondering if there is a well-understood best-practices or information resources for these kinds of frameworks that rely heavily on dynamic markup and inline-tagging that could be perceived as gibberish to something like a screen-reader or even a browser with JavaScript and CSS turned off.

Édouard Lopez
  • 40,270
  • 28
  • 126
  • 178
S Farron
  • 561
  • 1
  • 5
  • 10
  • ["A browser with no Javascript" is a myth.](http://a11yproject.com/posts/myth-screen-readers-dont-use-javascript/) Javascript and HTML have been around for mostly forever, I'd assume screenreaders can deal with reading the DOM, as rendered. (For instance, jQuery has a helper class that does "accessible hiding" of an element by absolutely positioning it offscreen in order to **prevent** screenreaders from skipping it.) – millimoose Sep 17 '13 at 15:14
  • 1
    From poking at WAI stuff for school, I also remember their specs have a whole lot of features aimed at letting screenreaders understand dynamic, AJAX-based web applications. (E.g. you can mark up an element as one whose contents will change dynamically so screenreaders will watch it for changes.) Generally, WAI's stuff should be the resource you're looking for: http://www.w3.org/WAI/ – millimoose Sep 17 '13 at 15:19
  • 8
    Whether the browser supports Javascript or not is beside the point. We must build our sites to fallback gracefully as browser features are disabled. Javascript can be toggled on or off at the whim of a user so we can't just assume they're always going to have it turned on. The article that was pointed to, in fact, suggests this be considered when building web applications. – S Farron Sep 17 '13 at 15:37
  • If your requirement is that your application must at all cost be usable without Javascript, regardless of the reason, then you simply have to accept that you'll have to sacrifice a good deal of dynamism. (Progressive enhancement helps, but it's laborious and for some features you can't not have AJAX.) What I am saying is: requiring Javascript does *not* make your site *inaccessible* to the visually impaired. They are not (and I'd wager there just are not) users who **can't** use Javascript. – millimoose Sep 17 '13 at 20:41
  • 1
    To put it differently: making a web site accessible to screenreader users is a completely different problem than making a web site usable to users with Javascript disabled. For the former: read WCAG, apply widely-supported WAI-ARIA attributes, or equivalent hacks. (I.e. focusing the element whose content changed dynamically.) For the latter: do not use any Javascript, or add it using progressive enhancement techniques. (A List Apart will gladly cover you in a deluge of articles on that topic.) – millimoose Sep 17 '13 at 20:45
  • 1
    A point to note: "progressive enhancement" is not the same as "graceful fallback" - they're different approaches to the same problem. The former seems to have greater mindshare these days. (I.e. you start with a fully functional server-side application, and add the dynamic behaviours that are available on the user's client. E.g. replace regular form submits with AJAX submits, dynamically add UI elements for all features that absolutely require Javascript, etc.) See: http://docs.webplatform.org/wiki/tutorials/graceful_degradation_versus_progressive_enhancement – millimoose Sep 17 '13 at 21:07
  • I see your point. It seems to me we're talking about two completely different issues: Accessibility and Progressive Enhancement. I'm seeing from several sources that Javascript can be considered ubiquitous across all browsing experiences when it comes to accessibility, and I should probably question the validity of claims to the contrary. Thanks for the clarification. – S Farron Sep 18 '13 at 19:44
  • Exactly. Even reasonably accessible content will be unusable by people who choose to not have Javascript enabled (for whichever reason, including but not restricted to using an old-ish screenreader.) Making your app usable by people who disable javascript implies that it will be accessible on accounts of being "basic" enough, but they're not the same concern. – millimoose Sep 18 '13 at 22:19
  • 2
    Even today, there are mainstream screen readers that *do not support or have very limited support for JavaScript*. A site being "accessible" and "working without JavaScript" are not two separate things. It doesn't mean that you have to have complete parity JavaScript on vs off. Obviously, the experiences you can provide will always be richer with JS on. However, everything mission critical should at least function without JS, or you very much *are* screwing over some of your users. – Chris Pratt Jun 25 '14 at 16:22
  • 1
    Vouching for @ChrisPratt, not all modern screen readers work well with JS. Also something that I don't see mentioned here as such: there are many people, including me, who use extensions like NoScript to willingly block JS (and Flash, Java, ...) for security reasons. Only selectively enabling stuff on a per-site basis. I have grown accustomed to the yellow bar in the bottom of my Iceweasel telling me how many scripts where blocked. Thus not only accessibly might be a reason to support techniques like Graceful Fallback or Progressive Enhancement, but security (for the mildly paranoid) as well. – Timusan Sep 25 '14 at 02:07
  • Here is a new Angular.js plugin to help with accessibility issues https://github.com/dequelabs/ngA11y – unobf Jan 05 '15 at 21:33

3 Answers3

31

All the same principles apply, such as using alt text for images, good use of headings, use the appropriate HTML(5) structures for content.

You might be creating it via JavaScript, but screen readers of the last ~5 years understand that, and use the browser's accessibility API to access the DOM. The non-JavaScript aspect is simply not an accessibility issue. The number of screen reader users without JavaScript is the same as the general population, therefore it comes across as fully formed HTML rather than the raw markup you see in development.

NB: I consider progressive enhancement a good approach, but with Angular.js you are deciding up-front not to take that approach. If you want to know about performance and progressive enhancement, I think this answered it.

Of course, you don't use Angular.js just to create standard content pages, so you need to get up to speed with the WAI-ARIA specification, and how to use ARIA in HTML. The specifies how to dynamically markup things that are not covered by traditional HTML practices, such as tabs, trees, grids etc.

For a practical example of WAI ARIA techniques in practice, I would have a look at the Whatsock technical style guide.

One difference compared to traditional websites are how you manage page updates, as you manage the keyboard focus rather than refresh the page. But apart from that, WAI-ARIA is the thing to read up on.

Community
  • 1
  • 1
AlastairC
  • 3,277
  • 21
  • 15
  • While these comments are all valid for Angular.js, very few of these are unique to a framework like Angular. jQueryUI, jQuery Mobile and plain JavaScript all suffer from these same issues. – unobf Jan 05 '15 at 21:37
  • 2
    Agreed, but the question asked about it, and also Angular does make an assumption that you are ignoring progressive enhancement, jQuery doesn't. – AlastairC Jan 12 '15 at 22:23
7

Traditionally, Angular did not encourage developers to code user interfaces "the right way"–it was too easy to create inaccessible custom element directives (such as ngClick on a div) and no accessibility support was provided. However, it has improved with the release of Angular 1.3x and the ngAria module. Now, by including ngAria in your application, certain ARIA attributes are automatically applied so that you don't have to manage them.

For example, the ngClick directive now applies tabIndex="0" and ngKeypress (as long as those options are not disabled) so that it is not as easy to create inaccessible click events. ngAria will also soon add role="button" to communicate the purpose of a clickable element: this can be overridden for other roles. See this pull request for more information: https://github.com/angular/angular.js/pull/10318

Another way ngAria can help is by adding aria-disabled to any use of ng-disabled. This ensures custom controls disabled by the framework will be accessible by default, such as:

<md-button ng-disabled="true">

With ngAria, this becomes:

<md-button ng-disabled="true" aria-disabled="true">

For the whole list of supported attributes, refer to the ngAria API docs: https://docs.angularjs.org/api/ngAria

ngAria will continue to evolve (and I wish it was just baked in instead of a module), but it's great to see accessibility finally supported by the core framework.

It's still up to each of us to keep accessibility in mind and code responsibly, but Angular should not get in your way any longer. Alistair's answer to this question has fantastic resources: I would definitely refer to those for tips on keyboard focus management, using ARIA in HTML, and so on. You can also refer to the new Angular.js Developer Guide for ngAria: https://docs.angularjs.org/guide/accessibility

And one more thing: if anyone has ideas for ngAria, by all means create a Github issue or submit a pull request! It's a community-driven effort.

Marcy Sutton
  • 907
  • 12
  • 22
  • 1
    Thanks for this explanation. I found this very question because I stumbled upon a website where the basic browser feature "open link in new window/tab" is broken because the website designer put `ngClick` on a `span` element, while a plain link would be perfect. They did use tabIndex, role but all this does not make it a real link, it's still fundamentally broken. It reminds me expressions like "rearranging the deck chairs on the Titanic", "a plaster on a wooden leg". So, people should start with respecting the basics of hypertext first. – Stéphane Gourichon Jun 03 '16 at 11:51
3

Your biggest issues with AngularJS and accessibility will be:

  1. Focus management - as soon as your route causes a section of content to be updated and that section contains the focus, the browser will send focus to the top of the document and screen reader and keyboard-only users will get lost. You will have to actively manage your focus
  2. Announcements of dynamic updates - data binding allows updates to occur to the DOM with no interaction with your JavaScript. If these updates are important, the screen reader users will have to be informed about these updates using aria-live regions. Getting these to work properly - especially on iOS will be tricky.
  3. Form validation - the AngularJS example all use elements for the error messages that get displayed when form validation fails. None of the associations are correct with the input fields and the same issues as mentioned under #2 will have to be addressed if displaying these automatically (especially when done using blur)
  4. title attribute updating - when your router changes your URL, you should be updating the title of the document

Other than that, it is just another HTML application.

This Github repo has some Angular.js directives and services for dealing with some of these problems https://github.com/dequelabs/ngA11y

unobf
  • 7,158
  • 1
  • 23
  • 36