Accessibility: Menus: Improve the menu items "Select All".

- changes "Select All" from a link to a checkbox
- the new checkbox is available only when JavaScript support is on
- semantically and for accessibility, a checkbox is a better user interface control because the available action is clear to all users and the selected state is communicated natively
- it's consistent with the existing pattern for the admin tables

Props birgire, audrasjb, afercia.
Fixes #47048.

Built from https://develop.svn.wordpress.org/trunk@46240


git-svn-id: http://core.svn.wordpress.org/trunk@46052 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrea Fercia 2019-09-23 12:42:58 +00:00
parent 9e26d98d7e
commit e43633b7d0
4 changed files with 41 additions and 49 deletions

View File

@ -593,11 +593,6 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
$checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args );
if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
$checkbox_items = preg_replace( '/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items );
}
echo $checkbox_items; echo $checkbox_items;
?> ?>
</ul> </ul>
@ -608,21 +603,10 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
<?php endif; ?> <?php endif; ?>
</div><!-- /.tabs-panel --> </div><!-- /.tabs-panel -->
<p class="button-controls wp-clearfix"> <p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
<span class="list-controls"> <span class="list-controls hide-if-no-js">
<a href=" <input type="checkbox" id="<?php echo esc_attr( $post_type_name . '-tab' ); ?>" class="select-all" />
<?php <label for="<?php echo esc_attr( $post_type_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
echo esc_url(
add_query_arg(
array(
$post_type_name . '-tab' => 'all',
'selectall' => 1,
),
remove_query_arg( $removed_args )
)
);
?>
#posttype-<?php echo $post_type_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a>
</span> </span>
<span class="add-to-menu"> <span class="add-to-menu">
@ -848,21 +832,10 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
</ul> </ul>
</div><!-- /.tabs-panel --> </div><!-- /.tabs-panel -->
<p class="button-controls wp-clearfix"> <p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
<span class="list-controls"> <span class="list-controls hide-if-no-js">
<a href=" <input type="checkbox" id="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>" class="select-all" />
<?php <label for="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
echo esc_url(
add_query_arg(
array(
$taxonomy_name . '-tab' => 'all',
'selectall' => 1,
),
remove_query_arg( $removed_args )
)
);
?>
#taxonomy-<?php echo $taxonomy_name; ?>" class="select-all aria-button-if-js"><?php _e( 'Select All' ); ?></a>
</span> </span>
<span class="add-to-menu"> <span class="add-to-menu">

View File

@ -208,7 +208,8 @@
// Add the items // Add the items
api.addItemToMenu(menuItems, processMethod, function(){ api.addItemToMenu(menuItems, processMethod, function(){
// Deselect the items and hide the ajax spinner // Deselect the items and hide the ajax spinner
checkboxes.removeAttr('checked'); checkboxes.prop( 'checked', false );
t.find( '.button-controls .select-all' ).prop( 'checked', false );
t.find( '.button-controls .spinner' ).removeClass( 'is-active' ); t.find( '.button-controls .spinner' ).removeClass( 'is-active' );
}); });
}); });
@ -1061,7 +1062,7 @@
attachTabsPanelListeners : function() { attachTabsPanelListeners : function() {
$('#menu-settings-column').bind('click', function(e) { $('#menu-settings-column').bind('click', function(e) {
var selectAreaMatch, panelId, wrapper, items, var selectAreaMatch, selectAll, panelId, wrapper, items,
target = $(e.target); target = $(e.target);
if ( target.hasClass('nav-tab-link') ) { if ( target.hasClass('nav-tab-link') ) {
@ -1071,7 +1072,7 @@
wrapper = target.parents('.accordion-section-content').first(); wrapper = target.parents('.accordion-section-content').first();
// upon changing tabs, we want to uncheck all checkboxes // upon changing tabs, we want to uncheck all checkboxes
$('input', wrapper).removeAttr('checked'); $( 'input', wrapper ).prop( 'checked', false );
$('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive'); $('.tabs-panel-active', wrapper).removeClass('tabs-panel-active').addClass('tabs-panel-inactive');
$('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active'); $('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active');
@ -1090,15 +1091,28 @@
} }
e.preventDefault(); e.preventDefault();
} else if ( target.hasClass('select-all') ) { } else if ( target.hasClass( 'select-all' ) ) {
selectAreaMatch = /#(.*)$/.exec(e.target.href); selectAreaMatch = target.closest( '.button-controls' ).data( 'items-type' );
if ( selectAreaMatch && selectAreaMatch[1] ) { if ( selectAreaMatch ) {
items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input'); items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );
if( items.length === items.filter(':checked').length )
items.removeAttr('checked'); if ( items.length === items.filter( ':checked' ).length && ! target.is( ':checked' ) ) {
else items.prop( 'checked', false );
items.prop('checked', true); } else if ( target.is( ':checked' ) ) {
return false; items.prop( 'checked', true );
}
}
} else if ( target.hasClass( 'menu-item-checkbox' ) ) {
selectAreaMatch = target.closest( '.tabs-panel-active' ).parent().attr( 'id' );
if ( selectAreaMatch ) {
items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );
selectAll = $( '.button-controls[data-items-type="' + selectAreaMatch + '"] .select-all' );
if ( items.length === items.filter( ':checked' ).length && ! selectAll.is( ':checked' ) ) {
selectAll.prop( 'checked', true );
} else if ( selectAll.is( ':checked' ) ) {
selectAll.prop( 'checked', false );
}
} }
} else if ( target.hasClass('submit-add-to-menu') ) { } else if ( target.hasClass('submit-add-to-menu') ) {
api.registerChange(); api.registerChange();
@ -1226,6 +1240,7 @@
pattern = /menu-item[(\[^]\]*/, pattern = /menu-item[(\[^]\]*/,
$items = $('<div>').html(resp).find('li'), $items = $('<div>').html(resp).find('li'),
wrapper = panel.closest( '.accordion-section-content' ), wrapper = panel.closest( '.accordion-section-content' ),
selectAll = wrapper.find( '.button-controls .select-all' ),
$item; $item;
if( ! $items.length ) { if( ! $items.length ) {
@ -1260,6 +1275,10 @@
$('.categorychecklist', panel).html( $items ); $('.categorychecklist', panel).html( $items );
$( '.spinner', panel ).removeClass( 'is-active' ); $( '.spinner', panel ).removeClass( 'is-active' );
wrapper.removeClass( 'has-no-menu-item' ); wrapper.removeClass( 'has-no-menu-item' );
if ( selectAll.is( ':checked' ) ) {
selectAll.prop( 'checked', false );
}
}, },
/** /**

File diff suppressed because one or more lines are too long

View File

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