Posts Tagged ‘Accessi’

ARIA Drag and Drop

Wednesday, May 18th, 2011

Drag and Drop operations have traditionally been very difficult for users who are blind, or otherwise cannot use a mouse. The ARIA Drag and Drop group of properties has solved the problem, although it is a bit cumbersome to implement.

ARIA uses aria-grabbed and aria-dropeffect to accomplish the task.

The Development Process

1. The developer must identify the draggable objects by setting the aria-grabbed to either true or false. Setting it to true indicates the object is grabbed. Setting it to false indicates it is draggable. Setting it to “” or “undefined” indicates it is not grabbable. Roles that support drag and drop are listitem and treeitem. The object must have a role declared for ARIA to work.

2. The developer must provide a way to select the draggable objects with the keyboard by setting the object’s aria_grabbed state to true. The JavaScript event onKeyDown can be used to detect if the user has selected an object by pressing the space key. Documentation also recommends using the Shift + Space to add a range of contiguous objects to the selection and control + shift to add non-contiguous items to the selection.

3. The developer must indicate the objects that can be drop targets using the aria-dropeffect. There are a number of properties that can be used to set aria-dropeffect:

  1. copy: A copy of the source object will be dropped on the target.
  2. move: The source object will be moved to the new location and removed from the orginial location.
  3. link: A shortcut link will be created.
  4. execute: the source is executed when it is dropped on the target.
  5. popup: Uses a popup menu that will let the user choose one of the other operations.
  6. none: No drop operation is supported. This is the default.

4. The developer is required to implement his/her own keyboard handlers to accomplish the dropping of the object. It is recommended that you follow the guidelines set out by the ARIA DHTML Styleguide. As an example, Control + M is used to drop once focus is on a droppable object. And ESC is used to cancle the operations.

5. After the operation the developer must:

  • Set all aria-dropeffect properties to “none” or remove them altogether.
  • Set all aria-grabbed of draggable objects to “false”.
  • Set all objects that are not grabbable must either omit the aria-grabbed property or have an aria-grabbed property set to “undefined”.
  • Set focus on the appropriate DOM element, and its role must also be determinable.

Note: The developer may want to consider adding a CSS style for the sighted keyboard only user to indicate visually what is draggable and where the drop points are located.

Alternative Method

The above steps are not for the faint of heart, and it takes a good knowledge of JavaScript to accomplish. So it may be appropriate to use an alternative approach. In fact, the alternative may be easier for screen reader users and keyboard only users.

As an example, if the task at hand envolves moving a picture to a album folder, you may want to provide a list of the pictures with check boxes that can be used to select all the images you wish to move. And then provide a drop down select list of the possible destination folders. This can be much easier in the long run.

Example 1: Creating a Draggable Object

Picture 1
Picture 2
Picture 3
Picture 4

Code


<div role="treeitem" aria-grabbed="false">Picture 1</div>
<div role="treeitem" aria-grabbed="true">Picture 2</div>
<div role="treeitem" aria-grabbed="undefined">Picture 3</div>
<div role="treeitem" aria-grabbed="">Picture 4</div>

Example 2: Creating a Drop Spot

Album 1
Album 2

Code


<div role="treeitem" aria-dropeffect="move">Album 1</div>
<div role="treeitem" aria-dropeffect="move">Album 2</div>

Example 3: Alternative

Picture 1
Picture 2
Albums:

Code


<input type="checkbox" id="picture1" aria-label="Select to move Picture 1">Picture 1 
<input type="checkbox" id="picture2" aria-label="Select to move Picture 2">Picture 2 
Albums:
<select aria-label="Select an Album in which to move the Pictures">
<option>Album 1</option>
<option>Album 2</option>
</select>
<input type="submit" value="Move Pictures">

Standards: