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.


git-svn-id: https://develop.svn.wordpress.org/trunk@41359 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrea Fercia 2017-09-09 14:49:53 +00:00
parent 6cbe8cba2e
commit 798c1894f4
1 changed files with 13 additions and 4 deletions

View File

@ -89,7 +89,12 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
}
if ( ( $parent_file && $item[2] == $parent_file ) || ( empty($typenow) && $self == $item[2] ) ) {
$class[] = ! empty( $submenu_items ) ? 'wp-has-current-submenu wp-menu-open' : 'current';
if ( ! empty( $submenu_items ) ) {
$class[] = 'wp-has-current-submenu wp-menu-open';
} else {
$class[] = 'current';
$aria_attributes .= 'aria-current="page"';
}
} else {
$class[] = 'wp-not-current-submenu';
if ( ! empty( $submenu_items ) )
@ -178,6 +183,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
continue;
$class = array();
$aria_attributes = '';
if ( $first ) {
$class[] = 'wp-first-item';
$first = false;
@ -192,8 +198,10 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
$self_type = ! empty( $typenow ) ? $self . '?post_type=' . $typenow : 'nothing';
if ( isset( $submenu_file ) ) {
if ( $submenu_file == $sub_item[2] )
if ( $submenu_file == $sub_item[2] ) {
$class[] = 'current';
$aria_attributes .= ' aria-current="page"';
}
// If plugin_page is set the parent must either match the current page or not physically exist.
// This allows plugin pages with the same hook to exist under different parents.
} elseif (
@ -201,6 +209,7 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
( isset( $plugin_page ) && $plugin_page == $sub_item[2] && ( $item[2] == $self_type || $item[2] == $self || file_exists($menu_file) === false ) )
) {
$class[] = 'current';
$aria_attributes .= ' aria-current="page"';
}
if ( ! empty( $sub_item[4] ) ) {
@ -224,9 +233,9 @@ function _wp_menu_output( $menu, $submenu, $submenu_as_parent = true ) {
$sub_item_url = add_query_arg( array( 'page' => $sub_item[2] ), 'admin.php' );
$sub_item_url = esc_url( $sub_item_url );
echo "<li$class><a href='$sub_item_url'$class>$title</a></li>";
echo "<li$class><a href='$sub_item_url'$class$aria_attributes>$title</a></li>";
} else {
echo "<li$class><a href='{$sub_item[2]}'$class>$title</a></li>";
echo "<li$class><a href='{$sub_item[2]}'$class$aria_attributes>$title</a></li>";
}
}
echo "</ul>";