Make WordPress Core

Changeset 41359


Ignore:
Timestamp:
09/09/2017 02:49:53 PM (7 years ago)
Author:
afercia
Message:

Administration: Admin menu: Use aria-current for the current active page.

The aria-current attribute is a simple, effective way to communicate to assistive
technologies which the current item within a set of items is. While the admin menu
structure isn't 100% ideal (the top-level item is repeated also as a sub-item)
adding aria-current="page" to the sub-items gives an important feedback to
assistive technologies users.

This change introduces aria-current for the first time in core. Worth noting
there are other places where it can be used to improve accessibility. These should
be addressed in separate tickets and patches.

Fixes #41589.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/menu-header.php

    r41200 r41359  
    9090
    9191        if ( ( $parent_file && $item[2] == $parent_file ) || ( empty($typenow) && $self == $item[2] ) ) {
    92             $class[] = ! empty( $submenu_items ) ? 'wp-has-current-submenu wp-menu-open' : 'current';
     92            if ( ! empty( $submenu_items ) ) {
     93                $class[] = 'wp-has-current-submenu wp-menu-open';
     94            } else {
     95                $class[] = 'current';
     96                $aria_attributes .= 'aria-current="page"';
     97            }
    9398        } else {
    9499            $class[] = 'wp-not-current-submenu';
     
    179184
    180185                $class = array();
     186                $aria_attributes = '';
    181187                if ( $first ) {
    182188                    $class[] = 'wp-first-item';
     
    193199
    194200                if ( isset( $submenu_file ) ) {
    195                     if ( $submenu_file == $sub_item[2] )
     201                    if ( $submenu_file == $sub_item[2] ) {
    196202                        $class[] = 'current';
     203                        $aria_attributes .= ' aria-current="page"';
     204                    }
    197205                // If plugin_page is set the parent must either match the current page or not physically exist.
    198206                // This allows plugin pages with the same hook to exist under different parents.
     
    202210                ) {
    203211                    $class[] = 'current';
     212                    $aria_attributes .= ' aria-current="page"';
    204213                }
    205214
     
    225234
    226235                    $sub_item_url = esc_url( $sub_item_url );
    227                     echo "<li$class><a href='$sub_item_url'$class>$title</a></li>";
     236                    echo "<li$class><a href='$sub_item_url'$class$aria_attributes>$title</a></li>";
    228237                } else {
    229                     echo "<li$class><a href='{$sub_item[2]}'$class>$title</a></li>";
     238                    echo "<li$class><a href='{$sub_item[2]}'$class$aria_attributes>$title</a></li>";
    230239                }
    231240            }
Note: See TracChangeset for help on using the changeset viewer.