Accessibility: Handle focus when closing the media modal.

When closing the media modal, by default focus should be moved back to the UI
control that was clicked to open the modal. The only exception is when inserting
images into the Visual or Text editor.

Fixes #38142.

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


git-svn-id: http://core.svn.wordpress.org/trunk@38595 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrea Fercia 2016-09-25 21:33:31 +00:00
parent 13f243747f
commit c3ad2eee78
5 changed files with 14 additions and 13 deletions

View File

@ -1111,13 +1111,6 @@
event.preventDefault();
// Remove focus from the `.insert-media` button.
// Prevents Opera from showing the outline of the button
// above the modal.
//
// See: https://core.trac.wordpress.org/ticket/22445
elem.blur();
if ( elem.hasClass( 'gallery' ) ) {
options.state = 'gallery';
options.title = wp.media.view.l10n.createGalleryTitle;

File diff suppressed because one or more lines are too long

View File

@ -6698,6 +6698,8 @@ Modal = wp.media.View.extend({
'keydown': 'keydown'
},
clickedOpenerEl: null,
initialize: function() {
_.defaults( this.options, {
container: document.body,
@ -6765,6 +6767,8 @@ Modal = wp.media.View.extend({
return this;
}
this.clickedOpenerEl = document.activeElement;
if ( ! this.views.attached ) {
this.attach();
}
@ -6815,8 +6819,12 @@ Modal = wp.media.View.extend({
// Hide modal and remove restricted media modal tab focus once it's closed
this.$el.hide().undelegate( 'keydown' );
// Put focus back in useful location once modal is closed
$('#wpbody-content').focus();
// Put focus back in useful location once modal is closed.
if ( null !== this.clickedOpenerEl ) {
this.clickedOpenerEl.focus();
} else {
$( '#wpbody-content' ).focus();
}
this.propagate('close');

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38651';
$wp_version = '4.7-alpha-38652';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.