Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What ARIA state role to use for current page in navigation

Recently I've been implementing ARIA into a web application and I found this question to be quite helpful in the improving the navigation parts.

After implementing this in all modules, I discovered this HTML validation error:

Attribute aria-selected not allowed on element a at this point.

Looking at the ARIA specification, I see that aria-selected is only used in roles gridcell, option, row, and tab. In my case, the role of the link is menuitem.

This is a representative sample of the HTML code:

<nav role=navigation>
    <ul role=menubar>
        <li role=presentation><a href='page1.php' role=menuitem>Page 1</a></li>
        <li role=presentation><a href='page2.php' role=menuitem>Page 2</a></li>
        <li role=presentation><a href='page3.php' role=menuitem aria-selected=true>Page 3</a></li>
        <li role=presentation><a href='page4.php' role=menuitem>Page 4</a></li>
    </ul>
</nav>

As you can see, this is taken on "page 3".

What is the correct ARIA role to use here?

like image 452
rink.attendant.6 Avatar asked Oct 26 '13 08:10

rink.attendant.6


2 Answers

you may also use aria-current="page" for describing current displayed page among navigation items.

like image 160
Jan Stanicek Avatar answered Jan 22 '23 13:01

Jan Stanicek


I believe that aria-selected is for 'widgets' that are one-tab stop, like a set of tabs that you then arrow around to select. The selected aspect is about which one is in focus, not which page you are on.

I would check out this as a well tested example: http://whatsock.com/tsg/Coding%20Arena/ARIA%20Menus/Horizontal%20(Internal%20Content)/demo.htm

From: http://whatsock.com/tsg/

For showing the current page I would probably use a more traditional method: Make it not a link. E.g:

<li><a href='page2.php'>Page 2</a></li>
<li><strong>Page 3</strong></li>

This also prevents people from clicking on the same-page link by accident (which I see quite often in usability testing). You can apply the same CSS to nav ul a and nav ul strong and then override the styling for the strong.

like image 36
AlastairC Avatar answered Jan 22 '23 12:01

AlastairC