Accessibility: Widgets: Conditionally wrap the tag cloud widget in a `<nav>` element.

If the theme declares support for the `html5` feature `navigation-widgets`, the tag cloud widget is now wrapped in a `<nav>` element to improve semantics and accessibility.

The `<nav>` elements are native landmark regions, which helps assistive technology users to navigate through them.

Follow-up to [48349] for other widgets.

Props audrasjb, justinahinon, ravipatel.
Fixes #51455. See #48170.
Built from https://develop.svn.wordpress.org/trunk@49177


git-svn-id: http://core.svn.wordpress.org/trunk@48939 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2020-10-16 18:32:06 +00:00
parent fd1c2cb401
commit 6dba11fb82
2 changed files with 18 additions and 1 deletions

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.6-alpha-49176';
$wp_version = '5.6-alpha-49177';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -90,11 +90,28 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
echo $args['before_title'] . $title . $args['after_title'];
}
$format = current_theme_supports( 'html5', 'navigation-widgets' ) ? 'html5' : 'xhtml';
/** This filter is documented in wp-includes/widgets/class-wp-nav-menu-widget.php */
$format = apply_filters( 'navigation_widgets_format', $format );
if ( 'html5' === $format ) {
// The title may be filtered: Strip out HTML and make sure the aria-label is never empty.
$title = trim( strip_tags( $title ) );
$aria_label = $title ? $title : $default_title;
echo '<nav role="navigation" aria-label="' . esc_attr( $aria_label ) . '">';
}
echo '<div class="tagcloud">';
echo $tag_cloud;
echo "</div>\n";
if ( 'html5' === $format ) {
echo '</nav>';
}
echo $args['after_widget'];
}