From 87b556a77a802fe9fac2e039d617d6105082770e Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 15 Jul 2015 18:43:50 +0000 Subject: [PATCH] Customizer: Fix element focus after menu item is deleted for keyboard accessibility. Also restores box shadow on focus. Props valendesigns. Fixes #32740. git-svn-id: https://develop.svn.wordpress.org/trunk@33279 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/customize-nav-menus.css | 5 +++++ src/wp-admin/js/customize-nav-menus.js | 28 ++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/wp-admin/css/customize-nav-menus.css b/src/wp-admin/css/customize-nav-menus.css index c266bb7e0a..136f94eb51 100644 --- a/src/wp-admin/css/customize-nav-menus.css +++ b/src/wp-admin/css/customize-nav-menus.css @@ -573,6 +573,11 @@ color: #f00; } +.menu-item-bar .item-delete:focus { + -webkit-box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8); + box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8); +} + .adding-menu-items .menu-item-bar .item-edit { display: none; } diff --git a/src/wp-admin/js/customize-nav-menus.js b/src/wp-admin/js/customize-nav-menus.js index b7bb7a0643..fefac723c6 100644 --- a/src/wp-admin/js/customize-nav-menus.js +++ b/src/wp-admin/js/customize-nav-menus.js @@ -1146,21 +1146,21 @@ $removeBtn.on( 'click', function() { // Find an adjacent element to add focus to when this menu item goes away - var $adjacentFocusTarget; - if ( control.container.next().is( '.customize-control-nav_menu_item' ) ) { - if ( ! $( 'body' ).hasClass( 'adding-menu-items' ) ) { - $adjacentFocusTarget = control.container.next().find( '.item-edit:first' ); - } else { - $adjacentFocusTarget = control.container.next().find( '.item-delete:first' ); - } - } else if ( control.container.prev().is( '.customize-control-nav_menu_item' ) ) { - if ( ! $( 'body' ).hasClass( 'adding-menu-items' ) ) { - $adjacentFocusTarget = control.container.prev().find( '.item-edit:first' ); - } else { - $adjacentFocusTarget = control.container.prev().find( '.item-delete:first' ); - } + var addingItems = true, $adjacentFocusTarget, $next, $prev; + + if ( ! $( 'body' ).hasClass( 'adding-menu-items' ) ) { + addingItems = false; + } + + $next = control.container.nextAll( '.customize-control-nav_menu_item:visible' ).first(); + $prev = control.container.prevAll( '.customize-control-nav_menu_item:visible' ).first(); + + if ( $next.length ) { + $adjacentFocusTarget = $next.find( false === addingItems ? '.item-edit' : '.item-delete' ).first(); + } else if ( $prev.length ) { + $adjacentFocusTarget = $prev.find( false === addingItems ? '.item-edit' : '.item-delete' ).first(); } else { - $adjacentFocusTarget = control.container.next( '.customize-control-nav_menu' ).find( '.add-new-menu-item' ); + $adjacentFocusTarget = control.container.nextAll( '.customize-control-nav_menu' ).find( '.add-new-menu-item' ).first(); } control.container.slideUp( function() {