Accessibility: Best Practices
Rather than reinvent the wheel I'll look at two collections of accessibility best practices: [WAI-ARIA Authoring Practices 1.1](https://www.w3.org/TR/wai-aria-practices-1.1/) and Ebay's [MIND Patterns: Accessibility Patterns for the Web](https://ebay.gitbooks.io/mindpatterns/) (suggested by Rob Dodson). we will take the accordion example from the ARIA Authoring Practices and explore what we need to have in an accessible component. Note that, as of this writing, MIND does not have suggestions for an accordion element. This is a longer exercise than the one we did for the button demo earlier. Longer because of the element complexity, because there are many more moving parts and because there is no native equivalent on the web platform. Before we get started there are a couple terminology items we need to get out of the way: headers and panels as they refer to the according object. **Accordion Header** Label for or thumbnail representing a section of content that also serves as a control for showing, and in some implementations, hiding the section of content. In some accordions, there are additional elements that are always visible adjacent to the accordion header. For instance, a menubutton may accompany each accordion header to provide access to actions that apply to that section. And, in some cases, a snippet of the hidden content may also be visually persistent. **Accordion Panel** Section of content associated with an accordion header. Next we look at the keyboard interactions that we need and should have for our **Keyboard Interaction** - Required elements - Enter or Space: - When focus is on the accordion header for a collapsed panel, expands the associated panel. If the implementation allows only one panel to be expanded, and if another panel is expanded, collapses that panel - When focus is on the accordion header for an expanded panel, collapses the panel if the implementation supports collapsing. Some implementations require one panel to be expanded at all times and allow only one panel to be expanded; so, they do not support a collapse function - Optional Elements - Down Arrow: If focus is on an accordion header, moves focus to the next accordion header. If focus is on the last accordion header, either does nothing or moves focus to the first accordion header - Up Arrow: If focus is on an accordion header, moves focus to the previous accordion header. If focus is on the first accordion header, either does nothing or moves focus to the last accordion header. - Home: When focus is on an accordion header, moves focus to the first accordion header - End: When focus is on an accordion header, moves focus to the last accordion header. - Control + Page Down: If focus is inside an accordion panel or on an accordion header, moves focus to the next accordion header. If focus is in the last accordion header or panel, either does nothing or moves focus to the first accordion header - Control + Page Up: If focus is inside an accordion panel, moves focus to the header for that panel. If focus is on an accordion header, moves focus to the previous accordion header. If focus is on the first accordion header, either does nothing or moves focus to the last accordion header. **ARIA Roles, States, and Properties:** - The title of each accordion header is contained in an element with role [button](https://www.w3.org/TR/wai-aria-1.1/#button) - Each accordion header `button` is wrapped in an element with role [heading](https://www.w3.org/TR/wai-aria-1.1/#heading) that has a value set for [aria-level](https://www.w3.org/TR/wai-aria-1.1/#aria-level) that is appropriate for the information architecture of the page - If the native host language has an element with an implicit `heading` and `aria-level`, such as an HTML heading tag, a native host language element may be used - The `button` element is the only element inside the `heading` element. That is, if there are other visually persistent elements, they are not included inside the `heading` element - If the accordion panel associated with an accordion header is visible, the header `button` element has [aria-expanded](https://www.w3.org/TR/wai-aria-1.1/#aria-expanded) set to `true`. If the panel is not visible, [aria-expanded](https://www.w3.org/TR/wai-aria-1.1/#aria-expanded) is set to `false` - The accordion header `button` element has [aria-controls](https://www.w3.org/TR/wai-aria-1.1/#aria-controls) set to the ID of the element containing the accordion panel content - If the accordion panel associated with an accordion header is visible, and if the accordion does not permit the panel to be collapsed, the header `button` element has [aria-disabled](https://www.w3.org/TR/wai-aria-1.1/#aria-disabled) set to `true` - Optionally, each element that serves as a container for panel content has role [region](https://www.w3.org/TR/wai-aria-1.1/#region) and [aria-labelledby](https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby) with a value that refers to the button that controls display of the panel - Avoid using the `region` role in circumstances that create landmark region proliferation, e.g., in an accordion that contains more than approximately 6 panels that can be expanded at the same time - Role `region` is especially helpful to the perception of structure by screen reader users when panels contain heading elements or a nested accordion ### The Code As with the button example we will look at the HTML, CSS and Javascript separately to get an idea of what is involved to build this accessible component. The HTML uses a description list to group together headers (using the `dt` element) and panels (using `dd`) The code introduces the following ARIA attributes, some of them seen in the button demo: - [role](https://www.w3.org/TR/wai-aria-1.1/#usage_intro) provides a way to clasify elements according to function, similar to the [Role 1.0 Recommendation](https://www.w3.org/TR/role-attribute/). The semantics provided in ARIA are specific to accessibility roles, the Roles Recommendation provides more generic use caases - [aria-disabled](https://www.w3.org/TR/role-attribute/) Indicates that the element is perceivable (we can see it and read it in the page) but disabled (we can't interact with it, so it is not editable or otherwise operable) - Used in conjunction with the `disabled` attribute - This is different than being hidden using the [aria-hidden](https://www.w3.org/TR/wai-aria-1.1/#aria-hidden) or being read-only using the [aria-readonly](https://www.w3.org/TR/wai-aria-1.1/#aria-readonly) - [aria-level](https://www.w3.org/TR/wai-aria-1.1/#aria-level) defines the position of the element within the page hierarchy - Multiple elements in a set may have the same value for this attribute - This attribute can be used to provide an explicit indication of the level when that is not possible to calculate from the document structure or the aria-owns attribute - [aria-expanded](https://www.w3.org/TR/wai-aria-1.1/#aria-expanded) indicates whether the element, or another grouping element it controls, is currently expanded or collapsed - If the element with the `aria-expanded` attribute controls the expansion of another grouping container that is not 'owned by' the element, the author should reference the container by using the `aria-controls` attribute. - [aria-controls](https://www.w3.org/TR/wai-aria-1.1/#aria-controls) Identifies the element (or elements) whose contents or presence are controlled by the current element - For the accordion we'll use the heading to control the associated panels - [aria-labelledby](https://www.w3.org/TR/wai-aria-1.1/#aria-labelledby) identifies the element (or elements) that labels the current element ```html