Skip to content
Permalink
Browse files

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.


git-svn-id: https://develop.svn.wordpress.org/trunk@46240 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
afercia committed Sep 23, 2019
1 parent 01b18e8 commit 42b5133a2557c0fd58dae731d8694408133ea339
Showing with 39 additions and 47 deletions.
  1. +31 −12 src/js/_enqueues/lib/nav-menu.js
  2. +8 −35 src/wp-admin/includes/nav-menu.php
@@ -208,7 +208,8 @@
// Add the items
api.addItemToMenu(menuItems, processMethod, function(){
// 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' );
});
});
@@ -1061,7 +1062,7 @@

attachTabsPanelListeners : function() {
$('#menu-settings-column').bind('click', function(e) {
var selectAreaMatch, panelId, wrapper, items,
var selectAreaMatch, selectAll, panelId, wrapper, items,
target = $(e.target);

if ( target.hasClass('nav-tab-link') ) {
@@ -1071,7 +1072,7 @@
wrapper = target.parents('.accordion-section-content').first();

// 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');
$('#' + panelId, wrapper).removeClass('tabs-panel-inactive').addClass('tabs-panel-active');
@@ -1090,15 +1091,28 @@
}

e.preventDefault();
} else if ( target.hasClass('select-all') ) {
selectAreaMatch = /#(.*)$/.exec(e.target.href);
if ( selectAreaMatch && selectAreaMatch[1] ) {
items = $('#' + selectAreaMatch[1] + ' .tabs-panel-active .menu-item-title input');
if( items.length === items.filter(':checked').length )
items.removeAttr('checked');
else
items.prop('checked', true);
return false;
} else if ( target.hasClass( 'select-all' ) ) {
selectAreaMatch = target.closest( '.button-controls' ).data( 'items-type' );
if ( selectAreaMatch ) {
items = $( '#' + selectAreaMatch + ' .tabs-panel-active .menu-item-title input' );

if ( items.length === items.filter( ':checked' ).length && ! target.is( ':checked' ) ) {
items.prop( 'checked', false );
} else if ( target.is( ':checked' ) ) {
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') ) {
api.registerChange();
@@ -1226,6 +1240,7 @@
pattern = /menu-item[(\[^]\]*/,
$items = $('<div>').html(resp).find('li'),
wrapper = panel.closest( '.accordion-section-content' ),
selectAll = wrapper.find( '.button-controls .select-all' ),
$item;

if( ! $items.length ) {
@@ -1260,6 +1275,10 @@
$('.categorychecklist', panel).html( $items );
$( '.spinner', panel ).removeClass( 'is-active' );
wrapper.removeClass( 'has-no-menu-item' );

if ( selectAll.is( ':checked' ) ) {
selectAll.prop( 'checked', false );
}
},

/**
@@ -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 );
if ( 'all' == $current_tab && ! empty( $_REQUEST['selectall'] ) ) {
$checkbox_items = preg_replace( '/(type=(.)checkbox(\2))/', '$1 checked=$2checked$2', $checkbox_items );
}
echo $checkbox_items;
?>
</ul>
@@ -608,21 +603,10 @@ function wp_nav_menu_item_post_type_meta_box( $object, $box ) {
<?php endif; ?>
</div><!-- /.tabs-panel -->

<p class="button-controls wp-clearfix">
<span class="list-controls">
<a href="
<?php
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>
<p class="button-controls wp-clearfix" data-items-type="posttype-<?php echo esc_attr( $post_type_name ); ?>">
<span class="list-controls hide-if-no-js">
<input type="checkbox" id="<?php echo esc_attr( $post_type_name . '-tab' ); ?>" class="select-all" />
<label for="<?php echo esc_attr( $post_type_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
</span>

<span class="add-to-menu">
@@ -848,21 +832,10 @@ function wp_nav_menu_item_taxonomy_meta_box( $object, $box ) {
</ul>
</div><!-- /.tabs-panel -->

<p class="button-controls wp-clearfix">
<span class="list-controls">
<a href="
<?php
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>
<p class="button-controls wp-clearfix" data-items-type="taxonomy-<?php echo esc_attr( $taxonomy_name ); ?>">
<span class="list-controls hide-if-no-js">
<input type="checkbox" id="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>" class="select-all" />
<label for="<?php echo esc_attr( $taxonomy_name . '-tab' ); ?>"><?php _e( 'Select All' ); ?></label>
</span>

<span class="add-to-menu">

0 comments on commit 42b5133

Please sign in to comment.
You can’t perform that action at this time.