ARIA Tree Markup

A tree is a useful tool for displaying hierarchy relationships. For example, in Windows Explorer a tree is used to show the hierarchy of folders. Trees have been used in web applications for some time, but until recently there was not a good way to convey these to assistive technology such as a screen reader. The most common approach was to use unordered nested lists and the user would have to figure out relationships by keeping track of the nesting to get an understanding of the hierarchy. Which could become tedious and confusing quickly. In addition, if each item was activatable, e.g., was a link, the user would have to do a lot of tabbing to get to an item that was of interest, negating the convenience of expanding and collapsing branches to skip past groups of items that were not what was desired at the moment.

While keyboard handling could be implemented for expanding and collapsing tree items, assistive technology still could not track the items or convey the state of expansion because the user agent (browser) was not providing the information.

WAI-ARIA has an answer to these problems. By using it the role and state information that is needed by assistive technology can now be provided. Namely, the roles of tree for the container object; tree item for each branch or leaf of the tree; and group for groups of tree items that are contained at a level. For some additional discussion of ARIA see an earlier post “ARIA resources.”

 

To illustrate how ARIA markup for a tree is employed let’s walk through an example. In order to focus on the ARIA markup we will leave out details of implementing event handlers that would make the tree respond to user events. A browser that supports ARIA such as Firefox 3 will provide the accessibility information through MSAA though so you can check the results with a screen reader that support ARIA or with Microsoft’s MSAA Inspector tool.

 

The tree

Let’s consider the following tree represented by nested lists:

 

  • Item 1
    • Item 1.1
    • Item 1.2
    • Item 1.3
  • Item 2

     

The HTML would be structured like this:

 

<ul>

    <li>Item 1

        <ul>

            <li>Item 1.1></li>

            <li>Item 2</li>

            <li>Item 3</li>

        </ul>

    </li>

    <li>Item 2</li>

</ul>

 

To turn this into a functioning tree, links can be added to each item that call JavaScript functions to control the presentation of the tree such as hiding and showing the sub-lists.

 

Tell AT that this is a tree

Roles

In order to tell the browser and the assistive technology that this is a tree, ARIA markup needs to be added. Three roles are used in a tree:

 

  • Tree
  • Group
  • Treeitem

     

    The tree role pertains to the container object, in other words the entire tree from the first item through the last item. Assigning the tree role to the unordered list that holds all of the stuff will do the trick for us:

    <ul role=”tree”>

     

    Each item in the tree, whether it is a root node, branch or leaf, is a treeitem. In our example each list item is defined as a treeitem, for example:

    <li role=”treeitem”>Item 1.1</li>

     

    Groups are used to define blocks of related items at the same level. For example, items 1.1 through 1.3 are in a group that expands from “Item 1″ in our example. This is defined using a role of group on the container for the group of items. In this example the nested unordered list is the container. The HTML looks like:

    <ul role=”group”>

     

State

A treeitem is either expanded or collapsed. In a collapsed state the items that are children of the treeitem are not displayed. The state of an item is defined by using the aria-expanded attribute. It has two values: true, false.

TO convey that the “Item 1″ group in our example is expanded we add aria-expanded = “true” to the list item:

<li role=”treeitem” aria-expanded=”true”>Item 1

 

Focus

By default lists do not receive keyboard focus in HTML. However, since this is to be an interactive tree we need to define tabindex for the items in the tree. It is important to define a tabindex for each element in the tree that is wanted to gain keyboard focus, or is not wanted to in cases where it would by default, e.g., a link. (We do not want links that are used in the tree for actions to each individually appear in the tab order. Instead we want the tree to be navigatable with arrow keys after receiving keyboard focus via the tab key, and the next press of the tab key should move past the tree.)

In order to do this we need to use two values of tabindex: 0 and -1. A tabindex of 0 places the element into the tab order, allowing the browser to determine the tab order. A tabindex of -1 keeps an element out of the tab order, but allows it to receive focus programmatically.

In this example, the container list element that is now defined as a tree needs to be placed into the tab order. Thus add a tabindex of 0:

<ul role=”tree” tabindex=”0″>

 

Providing a name when focused upon

The tree itself should also be given a label so that it accurately conveys itself when the user tabs to it. If an element elsewhere on the page is the best label then use that. Otherwise we can use the first item in the tree as long as the item is sufficient enough to name the tree. This will ensure that screen readers will have something to say when focus lands on the tree.

To label the tree we use the “aria-labelledby” attribute to point to a HTML element that has the text for the name that we need. The “aria-labelledby” attribute is placed in the container element—the list element in this example. For example if we have a DIV of:

<div ID=”treename”>Table of contents</div>

We can point to this using

<ul role=”tree” tabindex=”0″ aria-labelledby=”treename”>

 

Putting it together - almost

Combining what we have discussed to this point we get the following HTML with ARIA markup defining the tree.

 

<div ID=”treename”>Table of contents</div>

<ul role=”tree” tabindex=”0″ aria-labelledby=”treename”>

    <li role=”treeitem” aria-expanded=”true” tabindex=-1>Item 1

        <ul role=”group”>

            <li role=”treeitem” tabindex=”-1″>Item 1.1></li>

            <li role=”treeitem” tabindex=”-1″>Item 2</li>

            <li role=”treeitem” tabindex=”-1″>Item 3</li>

        </ul>

    </li>

    <li role=”treeitem” tabindex=”-1″>Item 2</li>

</ul>

 

When this is presented in an ARIA aware browser such as Firefox 3, the tree is presented through the accessibility API to assistive technology such as Microsoft Active Accessibility (MSAA) on Windows. Tree items are conveyed with their names and there state information such as “expanded” for the “Item 1.”

However, at the moment there is a problem. Instead of showing that the name of the first item is “Item 1″ the entire contents of the nested items are also be returned as in “Item 1 Item 1.1 Item 1.2 Item 1.3″. At first this is a puzzling situation as it appears that the name of the first item in our tree is “Item 1″ and it is defined that way in the list item. On closer inspection we discover that the first list item actually encapsulates the group of sub items. Hence the entire contents between the <li>…</li> tags is being set as the name of the first treeitem. This is not what we want!

ARIA has a solution! It is possible to define the label for an element by using the aria-labelledby attribute in ARIA. For those familiar with explicit labeling used in HTML forms, this is a similar idea. It is more flexible in that any element containing text can be assigned, instead of just a Label element. To fix the problem we just need to explain to the browser and assistive technology that we only want “Item 1″ to be used as the name of the first node in the tree.

We can do this by using a Span element and setting it as the label for the treeitem:

<li role=”treeitem” aria-expanded=”true” aria-labelledby=”i1″ tabindex=-1><span id=”i1″>Item 1</span>

 

Final tree markup

The final markup for this tree using ARIA is now:

<div ID=”treename”>Table of contents</div>

<ul role=”tree” tabindex=”0″ aria-labelledby=”treename”>

    <li role=”treeitem” aria-expanded=”true” aria-labelledby=”i1″ tabindex=-1><span id=”i1″>Item 1</span>

        <ul role=”group”>

            <li role=”treeitem” tabindex=”-1″>Item 1.1></li>

            <li role=”treeitem” tabindex=”-1″>Item 2</li>

            <li role=”treeitem” tabindex=”-1″>Item 3</li>

        </ul>

    </li>

    <li role=”treeitem” aria-labelledby=”i2″ tabindex=”-1″><span id=”i2″>Item 2</span></li>

</ul>

 

Remember that when the tree is live and responding to user events that change the state of items such as expanding and collapsing branches, the ARIA information needs to be updated. For example, if “Item 1″ is collapsed the aria-expanded attribute needs to be set to “false”. Finally if the tree is very large and not all of it is loaded into the DOM at once additional management needs to be done such as using “aria-posinset.”

 

References

123 Responses to “ARIA Tree Markup”

  1. Travis Roth’s Weblog » Blog Archive » Using ARIA and jQuery to build an accessible tree – part 1 Says:

    [...] Roth’s Weblog Sports, business, accessibility, and who knows?… « ARIA Tree Markup Programmatically Customizable GUI [...]

  2. DOUG Says:

    PillSpot.org. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Pillspot.org. Herbal-supplements@buy.online” rel=”nofollow”>.…

    Categories: Anxiety/Sleep Aid.Pain Relief.Stop SmokingVitamins/Herbal Supplements.Mental HealthAntidepressants.Mens Health.Antidiabetic.Eye Care.Antibiotics.Blood Pressure/Heart.Skin Care.Stomach.Anti-allergic/Asthma.Womens Health.Antiviral.Weight…

  3. uk MacBook Apple/ Says:

    r\x3dh http://AWESOMEBABYCLOTHES.INFO/tag/r\x3dh : r\x3dh…

    uk MacBook Apple/…

  4. cavo Says:

    ieee http://nlancomezheqm.AUTOSECTIONS.INFO/tag/cavo+IEEE+ieee/ : ieee…

    IEEE…

  5. n Says:

    n http://ncygox-v7jq.AUTOSECTIONS.INFO/tag/review+n+2/ : review…

    n…

  6. To Says:

    From http://irecording2jhaoch.copious-systems.com/tag/From+Vcr+To+Dvd+VHS+dvd/ : To…

    dvd…

  7. for Says:

    for http://gbestlx0v.AWESOMEBABYCLOTHES.INFO/tag/Teeter+Tables+for/ : Teeter…

    Tables…

  8. Monroe Says:

    Car http://dhy.6bf.201i.co : Car…

    Shocks…

  9. Alexander Says:

    buy@viagra.online” rel=”nofollow”>…

    Need cheap generic VIAGRA?…

  10. ANGEL Says:

    Order@Coral.Calcium.Online” rel=”nofollow”>..

    Buygeneric pills…

  11. SALVADOR Says:

    Purchase@Abilify.Without.Prescription” rel=”nofollow”>..

    Buygeneric meds…

  12. DUSTIN Says:

    Cheap@Generic.Abilify” rel=”nofollow”>..

    Buygeneric drugs…

  13. EDUARDO Says:

    Cheap@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>..

    Buygeneric pills…

  14. BRANDON Says:

    Buy@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>..

    Buyno prescription…

  15. JEFFREY Says:

    Order@Cheap.Acai” rel=”nofollow”>…

    Buynow it…

  16. SALVADOR Says:

    Cheap@Acai.Online” rel=”nofollow”>…

    Buynow…

  17. TERRENCE Says:

    Cheap@Generic.Acai” rel=”nofollow”>..

    Buyit now…

  18. DONNIE Says:

    Buy@Discount.Coral.Calcium” rel=”nofollow”>..

    Buywithout prescription…

  19. ENRIQUE Says:

    Purchase@Cheap.Coral.Calcium” rel=”nofollow”>.

    Buynow it…

  20. ROY Says:

    Purchase@Cheap.Coral.Calcium” rel=”nofollow”>…

    Buywithout prescription…

  21. PERRY Says:

    Purchase@Cheap.Abana” rel=”nofollow”>…

    Buywithout prescription…

  22. LEWIS Says:

    Cheap@Abilify.Online” rel=”nofollow”>..

    Buynow it…

  23. RALPH Says:

    Buy@Cheap.Acai” rel=”nofollow”>…

    Buygeneric drugs…

  24. SAMUEL Says:

    Buy@Cheap.Acai” rel=”nofollow”>…

    Buygeneric drugs…

  25. FELIX Says:

    Order@Acai.Online” rel=”nofollow”>…

    Buyit now…

  26. CHARLIE Says:

    Order@Cheap.Acai” rel=”nofollow”>..

    Buynow it…

  27. WALLACE Says:

    Get@Acai.Online” rel=”nofollow”>…

    Buygeneric drugs…

  28. VICTOR Says:

    Buy@Acai.Without.Prescription” rel=”nofollow”>.

    Buygeneric drugs…

  29. TONY Says:

    Buy@Discount.Energy.Boost” rel=”nofollow”>.…

    Buynow it…

  30. NATHAN Says:

    Order@Discount.Energy.Boost” rel=”nofollow”>.…

    Buynow it…

  31. ADAM Says:

    Buy@Discount.Accupril” rel=”nofollow”>.…

    Buyno prescription…

  32. BILLY Says:

    Cheap@Accupril.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  33. JIMMY Says:

    Buy@Accutane.Online” rel=”nofollow”>.…

    Buygeneric drugs…

  34. BRUCE Says:

    Order@Cheap.Accutane” rel=”nofollow”>.…

    Buygeneric drugs…

  35. CARL Says:

    Cheap@Accutane.Online” rel=”nofollow”>.…

    Buygeneric meds…

  36. ANDREW Says:

    Cheap@Aciphex.Without.Prescription” rel=”nofollow”>.…

    Buynow it…

  37. SERGIO Says:

    Buy@Generic.Actonel.35mg” rel=”nofollow”>.

    Buyno prescription luw…

  38. VICTOR Says:

    Generic@Actonel.35mg.Without.Prescription” rel=”nofollow”>..

    Buygeneric pills zdg…

  39. DARYL Says:

    Order@Cheap.Actoplus.Met” rel=”nofollow”>..

    Buygeneric drugs krg…

  40. CLIFTON Says:

    Buy@Generic.Actos.15mg.30mg” rel=”nofollow”>..

    Buygeneric meds qmo…

  41. RAY Says:

    Cheap@Acular.Online” rel=”nofollow”>.

    Buygeneric drugs zfk…

  42. RODNEY Says:

    Order@Cheap.Coral.Calcium” rel=”nofollow”>..

    Buygeneric drugs lzt…

  43. LLOYD Says:

    Order@Cheap.Abilify” rel=”nofollow”>…

    Buywithout prescription xiu…

  44. MARCUS Says:

    Buy@Abilify.5mg.10mg.15mg.20mg.30mg” rel=”nofollow”>..

    Buynow it vhx…

  45. PHILIP Says:

    Abilify@5mg.10mg.15mg.20mg.30mg.Without.Prescription” rel=”nofollow”>…

    Buygeneric meds svb…

  46. ALFRED Says:

    Buy@Cheap.Acai” rel=”nofollow”>..

    Buyno prescription wkp…

  47. BRUCE Says:

    Order@Acai.Online” rel=”nofollow”>..

    Buyno prescription jui…

  48. MARION Says:

    Order@Cheap.Acai” rel=”nofollow”>..

    Buyno prescription gdt…

  49. LEROY Says:

    Cheap@Acai.Online” rel=”nofollow”>…

    Buyit now sge…

  50. VINCENT Says:

    Purchase@Cheap.Energy.Boost” rel=”nofollow”>.

    Buyit now ojb…

  51. AUSTIN Says:

    Order@Cheap.Accupril” rel=”nofollow”>.

    Buynow it fnp…

  52. TRAVIS Says:

    Buy@Cheap.Accutane” rel=”nofollow”>..

    Buyno prescription tao…

  53. MARION Says:

    Order@Discount.Accutane” rel=”nofollow”>.

    Buygeneric drugs mby…

  54. JASON Says:

    Purchase@Cheap.Accutane” rel=”nofollow”>…

    Buywithout prescription ccw…

  55. BRUCE Says:

    Cheap@Generic.Accutane.10mg.20mg” rel=”nofollow”>…

    Buynow it zdg…

  56. RONNIE Says:

    Accutane@10mg.20mg.Without.Prescription” rel=”nofollow”>..

    Buygeneric drugs ajd…

  57. RONALD Says:

    Buy@Aciphex.Online” rel=”nofollow”>.

    Buygeneric drugs itj…

  58. MARVIN Says:

    Aciphex@20mg.Without.Prescription” rel=”nofollow”>.

    Buynow it lmg…

  59. MITCHELL Says:

    Buy@Discount.Acomplia” rel=”nofollow”>..

    Buydrugs without prescription faj…

  60. REGINALD Says:

    Order@Actonel.Without.Prescription” rel=”nofollow”>…

    Buydrugs without prescription jlg…

  61. GERARD Says:

    Order@Advair.Online” rel=”nofollow”>..

    Buyit now irl…

  62. BRYAN Says:

    Cheap@Advair.Online” rel=”nofollow”>.

    Buygeneric drugs nih…

  63. ALVIN Says:

    Buy@Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>..< /blo…

    Buygeneric meds dxy…

  64. RUSSELL Says:

    Buy@Advair.25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg” rel=”nofollow”>…< /bl…

    Buygeneric drugs vbr…

  65. EVAN Says:

    < a href=”http://trig.com/advair5771/biography/?ml=Advair-25mcg/50mcg-25mcg/125mcg-25mcg/250mcg-50mcg/500mcg-50mcg/100mcg-50mcg/250mcg-Without-Prescription Advair@25mcg50mcg.25mcg125mcg.25mcg250mcg.50mcg500mcg.50mcg100mcg.50mcg250mcg.Without.Pr

    Buydrugs without prescription ygy…

  66. OLIVER Says:

    advair@copd.advertising.campaign” rel=”nofollow”>..

    Buynow…

  67. DAN Says:

    buy@amoxicillin.500mg” rel=”nofollow”>.

    Buynow it…

  68. FERNANDO Says:

    arimidex@or.nolvadex.steriods” rel=”nofollow”>..

    Buywithout prescription…

  69. greg Says:

    Download@pop.Rock” rel=”nofollow”>…

    Search rock US Charts…

  70. STEPHEN Says:

    warfarin zoloft

    Buy_drugs without prescription…

  71. CHARLIE Says:

    do cats carry ringworm

    Buy_generic meds…

  72. PATRICK Says:

    recent advances in cancer breast

    Buy_now…

  73. LEON Says:

    steroids abuse sexual dysfunction

    Buy_it now…

  74. ROGER Says:

    soft food diet ideas

    Buy_drugs without prescription…

  75. BILLY Says:

    hiv aids in california in 1997

    Buy_generic pills…

  76. FRANCIS Says:

    impact rating journal of clinical psychology

    Buy_now it…

  77. STUART Says:

    viagra in the uk

    Buy_no prescription…

  78. MILTON Says:

    tuna during pregnancy

    Buy_generic meds…

  79. KENNETH Says:

    arimidex and marathon

    Buy_generic drugs…

  80. JORGE Says:

    adult circumcisions and complications

    Buy_generic meds…

  81. FREDERICK Says:

    good and bad drugs

    Buy_without prescription…

  82. HOWARD Says:

    is hepatitis b contagious

    Buy_generic pills…

  83. KEVIN Says:

    gestational surrogacy

    Buy_now…

  84. FREDDIE Says:

    combination food diet

    Buy_drugs without prescription…

  85. BILLY Says:

    drug rehab center british columbia

    Buy_generic drugs…

  86. ALLEN Says:

    buying prescription drugs in mexico

    Buy_now it…

  87. WADE Says:

    faye sick lung cancer

    Buy_drugs without prescription…

  88. RENE Says:

    terbutaline autism claim

    Buy_no prescription…

  89. ANDREW Says:

    iv zofran

    Buy_drugs without prescription…

  90. ANDRE Says:

    blood pregnancy test jacksonville fl

    Buy_generic meds…

  91. AUSTIN Says:

    does birth control control moods

    Buy_generic drugs…

  92. JOSHUA Says:

    chf vs pulmonary edema

    Buy_generic drugs…

  93. DUSTIN Says:

    weight loss tricks for 40 somethings

    Buy_drugs without prescription…

  94. MARCUS Says:

    hypertension police ma

    Buy_drugs without prescription…

  95. ALBERT Says:

    psychostimulant treatment of depression

    Buy_drugs without prescription…

  96. CLINTON Says:

    copd lung sounds

    Buy_it now…

  97. DONALD Says:

    canine medi cam rx

    Buy_generic drugs…

  98. VERNON Says:

    azithromycin doxycycline over the counter

    Buy_generic pills…

  99. RICK Says:

    forensic drug test swab

    Buy_no prescription…

  100. TERRY Says:

    social interaction anxiety

    Buy_without prescription…

  101. ROGER Says:

    how to make glucose water

    Buy_it now…

  102. HARRY Says:

    how can i lower my cholesterol

    Buy_generic drugs…

  103. RUSSELL Says:

    dr loss phil ultimate weight

    Buy_no prescription…

  104. JIM Says:

    indomethacin opthalmic drops

    Buy_generic pills…

  105. MARION Says:

    foods with triglycerides in them

    Buy_generic drugs…

  106. FERNANDO Says:

    hormone shot for prostate cancer

    Buy_generic drugs…

  107. STEPHEN Says:

    advisory group on hepatitis uk

    Buy_no prescription…

  108. COREY Says:

    tobacco alternatives herbal

    Buy_generic drugs…

  109. DAN Says:

    flat warts and probiotics

    Buy_generic drugs…

  110. ENRIQUE Says:

    medicare drugs covered

    Buy_generic meds…

  111. VIRGIL Says:

    state of arizona ontiveros drug

    Buy_now it…

  112. JOHNNIE Says:

    black molley slang drug name

    Buy_generic drugs…

  113. ALFRED Says:

    lexapro versus prozac differences

    Buy_without prescription…

  114. SHANE Says:

    sample ncp for diabetes

    Buy_without prescription…

  115. TRACY Says:

    what year was advil introduced

    Buy_now it…

  116. jordan Says:

    Download@pop.Rock” rel=”nofollow”>.

    Buy rock US Charts…

  117. HUGH Says:

    depo@provera.bone.loss” rel=”nofollow”>…

    Buygeneric drugs…

  118. CORY Says:


    BUY CHEAP DRUGS : -==== Anti Convulsants Drugs ====-

    Purchase Quality Generic Drugs Now!…

  119. WALLACE Says:


    Buy Viagra

    Check Quality Generic Pills Today!…

  120. dallas tx Says:

    dallas tx…

    Travis Roth’s Weblog » Blog Archive » ARIA Tree Markup…

  121. bestininternetmarketing.com Says:

    bestininternetmarketing.com…

    Travis Roth’s Weblog » Blog Archive » ARIA Tree Markup…

  122. mouse click the up coming webpage Says:

    mouse click the up coming webpage…

    Travis Roth’s Weblog » Blog Archive » ARIA Tree Markup…

  123. Find Out More Says:

    Find Out More…

    Travis Roth’s Weblog » Blog Archive » ARIA Tree Markup…