diff --git a/src/wp-admin/js/customize-controls.js b/src/wp-admin/js/customize-controls.js index 9f385a003b..e6270ee0e6 100644 --- a/src/wp-admin/js/customize-controls.js +++ b/src/wp-admin/js/customize-controls.js @@ -5365,16 +5365,20 @@ // Focus on the control that is associated with the given setting. api.previewer.bind( 'focus-control-for-setting', function( settingId ) { - var matchedControl; + var matchedControls = []; api.control.each( function( control ) { var settingIds = _.pluck( control.settings, 'id' ); if ( -1 !== _.indexOf( settingIds, settingId ) ) { - matchedControl = control; + matchedControls.push( control ); } } ); - if ( matchedControl ) { - matchedControl.focus(); + // Focus on the matched control with the lowest priority (appearing higher). + if ( matchedControls.length ) { + matchedControls.sort( function( a, b ) { + return a.priority() - b.priority(); + } ); + matchedControls[0].focus(); } } ); diff --git a/src/wp-includes/js/customize-selective-refresh.js b/src/wp-includes/js/customize-selective-refresh.js index 0735b237c8..d3b81db6d7 100644 --- a/src/wp-includes/js/customize-selective-refresh.js +++ b/src/wp-includes/js/customize-selective-refresh.js @@ -312,14 +312,15 @@ wp.customize.selectiveRefresh = ( function( $, api ) { * @since 4.5.0 */ showControl: function() { - var partial = this, settingId = partial.params.primarySetting, menuSlug; + var partial = this, settingId = partial.params.primarySetting; if ( ! settingId ) { settingId = _.first( partial.settings() ); } if ( partial.getType() === 'nav_menu' ) { - menuSlug = partial.params.navMenuArgs.theme_location; - if ( menuSlug ) { - settingId = 'nav_menu_locations[' + menuSlug + ']'; + if ( partial.params.navMenuArgs.theme_location ) { + settingId = 'nav_menu_locations[' + partial.params.navMenuArgs.theme_location + ']'; + } else if ( partial.params.navMenuArgs.menu ) { + settingId = 'nav_menu[' + String( partial.params.navMenuArgs.menu ) + ']'; } } api.preview.send( 'focus-control-for-setting', settingId );