Skip to content
easeweb
Search topics

Tree views keyboards can't open and screen readers flatten

A sidebar's sections are clickable divs, or tree roles without their keys and levels, so keyboards can't open them and a screen reader hears one flat list.

WCAG 2.2
SC 1.3.1ASC 2.1.1ASC 4.1.2A
Required by
Section 508 · EN 301 549 (EU)
Broken <div class="section">Account</div>
The accessibility problem illustrated: Motor:How do I open Account?
01

The problem

Keyboard users can't open a sidebar's sections to reach the pages inside them, and screen reader users can't tell which section a page is in, how deep it sits, or whether a section is open

02

Try it

Open Account and reach Change your email using only the keyboard

  • Broken 1: press Tab. It stops only on the links already showing, never on a section, so Account can't be opened.

  • Broken 2: the same divs, with tree roles added. Tab still skips every section, the arrow keys do nothing, and the panel says every item is level 1 and never says whether a section is open.

  • Apply the fix. In the tree view, the arrow keys move and open sections, and Home and End jump to the ends.

Broken Can you fix this?

A recreated demo. The broken version is intentionally inaccessible.

03

The fix

Let the keyboard open each section, and keep its nesting

Before

Sections built from clickable divs

<div class="help-nav">  <div class="section">Getting started</div>  <div class="pages" hidden>    <a href="/help/create-account">Create an account</a>    <a href="/help/invite-your-team">Invite your team</a>  </div>  <div class="section is-open">Billing</div>  <div class="pages">    <a href="/help/plans">Plans and prices</a>    <div class="section">Payment methods</div>    <div class="pages" hidden>      <a href="/help/cards">Cards</a>      <a href="/help/bank-transfer">Bank transfer</a>    </div>    <a href="/help/invoices">Invoices</a>  </div>  <div class="section">Account</div>  <div class="pages" hidden>    <a href="/help/change-email">Change your email</a>    <a href="/help/delete-account">Delete your account</a>  </div></div>
What is wrong3 points
  • The keyboard can't reach a closed section's pages. The sections respond only to click and take no focus.
  • A screen reader can't tell that a section opens, or whether it is open. Nothing in the markup says so.
  • A screen reader hears the pages as one flat list. Nothing says the links after a section belong to it: the nesting is padding.
After

Nested lists with a button for each section

<nav class="help-nav" aria-label="Help topics">  <ul>    <li>      <button type="button" aria-expanded="false" aria-controls="help-start">Getting started</button>      <ul id="help-start" hidden>        <li><a href="/help/create-account">Create an account</a></li>        <li><a href="/help/invite-your-team">Invite your team</a></li>      </ul>    </li>    <li>      <button type="button" aria-expanded="true" aria-controls="help-billing">Billing</button>      <ul id="help-billing">        <li><a href="/help/plans">Plans and prices</a></li>        <li>          <button type="button" aria-expanded="false" aria-controls="help-payment">Payment methods</button>          <ul id="help-payment" hidden>            <li><a href="/help/cards">Cards</a></li>            <li><a href="/help/bank-transfer">Bank transfer</a></li>          </ul>        </li>        <li><a href="/help/invoices">Invoices</a></li>      </ul>    </li>    <li>      <button type="button" aria-expanded="false" aria-controls="help-account">Account</button>      <ul id="help-account" hidden>        <li><a href="/help/change-email">Change your email</a></li>        <li><a href="/help/delete-account">Delete your account</a></li>      </ul>    </li>  </ul></nav>
How it is fixed4 steps
  1. Put the pages in a nav, as a list, and nest each section's pages in a list inside its list item. The structure is then in the markup: screen readers announce a list and how many items it has as you move into it, and some also say how deeply it is nested.
  2. Make each section a native button. Tab reaches it and Enter and Space open it, with no key handling to write.
  3. Give each button aria-expanded, set in the click handler, so a screen reader says "Billing, button, expanded" or "collapsed". The arrow is drawn from it.
  4. Keep hidden on a closed section's list, so its links stay out of the Tab order. The open section's list follows its button, so the next Tab goes straight into it.

This is the disclosure pattern that the ARIA Authoring Practices advise for navigation with expandable groups of links. It fixes both Befores and passes 1.3.1, 2.1.1 and 4.1.2.

Why this fix: Use native HTML first

04

Verify the fix

5 checks, no mouse.

Test with: Keyboard, Screen reader, Forced colors, Zoom

0 of 5 checked

Record the OS, browser and assistive-technology versions, the build, the date, and the actual result of each step. Repeat after the sidebar, its component or its library changes.

How screen readers handle aria-expanded

Limits

This is a starting pattern, not a guarantee for every application. The scripts are minimal sketches: the tree has no type-ahead, no multiple selection and no loading on demand. A dropdown menu across the top of a page is a different pattern, covered in hover-only dropdowns, or ones that never say they are open, and a single section that opens and closes is covered in show and hide buttons that don't say whether they are open. A file tree that also lets people move items by dragging them needs a way without dragging, as drag-and-drop boards that only a mouse can use explains. Table rows that open into child rows, such as tasks with subtasks, are a tree grid, a pattern of its own, covered in expandable table rows a keyboard can't open. Test the complete journey with your target assistive technology.

This is a recreated teaching example, not a finding about a named client. The code is a starting pattern: test it in your own product. No completed assistive-technology test is claimed here.

EaseWeb service

Fixed it? Keep it from coming back.

I turn guides like this one into rules your coding agents follow and checks your CI runs. Then I retest by hand with a keyboard and screen readers, periodically.

See the service