public static class Roles extends Object
A factory providing each concrete role in the ARIA specification. Each role implements methods that a GWT application can use to modify the appropriate DOM attributes for that role.
For example, suppose our GWT app has a image button and we want to make it visible in screen readers as a button with some help text. To do this, we add a button role to the image and set the ARIA label property to the help text that the screen reader can use:
Roles.getButtonRole().set(img.getElement()); Roles.getButtonRole().setAriaLabelProperty(img.getElement(), "some help text");
Most ARIA properties have a prefix of "aria-" and only affect screen readers, but there is one exception: the "tabindex" property is the same one used for tab order in regular widgets. For example, to set tabindex to 0 for the button:
Roles.getButtonRole().setTabindexExtraAttribute(img.getElement(), 0);
When the button changes state (it's enabled or disabled), we can change the ARIA enabled state to match, like this:
Roles.getButtonRole().setAriaEnabledState(img.getElement(), isEnabled);
ARIA distinguishes between properties (which change rarely and could be set in static HTML) and states (which need to be updated in response to user input). This distinction can get a bit blurry when a GWT app updates the DOM dynamically. Generally you should update ARIA attributes at the same time that you change the CSS styles on a DOM node, so that a screen reader will see the same state as someone viewing the page visually.
The role interfaces form a hierarchy whose root is the Role
interface, which contains
generic methods that aren't specific to a role. Some abstract roles include:
WidgetRole
, for DOM elements that represent either standalone or composite widgets.
CompositeRole
, for widgets that contain other widgets.StructureRole
, for DOM elements that are part of the page layout.LandmarkRole
, for DOM elements defining common regions of a page.WindowRole
, for DOM elements that define windows and dialogs.Copyright © 2018. All rights reserved.