Make WordPress Core

Changeset 38652


Ignore:
Timestamp:
09/25/2016 09:32:10 PM (8 years ago)
Author:
afercia
Message:

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.

Location:
trunk/src/wp-includes/js
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/js/media-editor.js

    r38118 r38652  
    11121112                    event.preventDefault();
    11131113
    1114                     // Remove focus from the `.insert-media` button.
    1115                     // Prevents Opera from showing the outline of the button
    1116                     // above the modal.
    1117                     //
    1118                     // See: https://core.trac.wordpress.org/ticket/22445
    1119                     elem.blur();
    1120 
    11211114                    if ( elem.hasClass( 'gallery' ) ) {
    11221115                        options.state = 'gallery';
  • trunk/src/wp-includes/js/media-views.js

    r37755 r38652  
    66996699    },
    67006700
     6701    clickedOpenerEl: null,
     6702
    67016703    initialize: function() {
    67026704        _.defaults( this.options, {
     
    67666768        }
    67676769
     6770        this.clickedOpenerEl = document.activeElement;
     6771
    67686772        if ( ! this.views.attached ) {
    67696773            this.attach();
     
    68166820        this.$el.hide().undelegate( 'keydown' );
    68176821
    6818         // Put focus back in useful location once modal is closed
    6819         $('#wpbody-content').focus();
     6822        // Put focus back in useful location once modal is closed.
     6823        if ( null !== this.clickedOpenerEl ) {
     6824            this.clickedOpenerEl.focus();
     6825        } else {
     6826            $( '#wpbody-content' ).focus();
     6827        }
    68206828
    68216829        this.propagate('close');
  • trunk/src/wp-includes/js/media/views/modal.js

    r33337 r38652  
    2525    },
    2626
     27    clickedOpenerEl: null,
     28
    2729    initialize: function() {
    2830        _.defaults( this.options, {
     
    9294        }
    9395
     96        this.clickedOpenerEl = document.activeElement;
     97
    9498        if ( ! this.views.attached ) {
    9599            this.attach();
     
    142146        this.$el.hide().undelegate( 'keydown' );
    143147
    144         // Put focus back in useful location once modal is closed
    145         $('#wpbody-content').focus();
     148        // Put focus back in useful location once modal is closed.
     149        if ( null !== this.clickedOpenerEl ) {
     150            this.clickedOpenerEl.focus();
     151        } else {
     152            $( '#wpbody-content' ).focus();
     153        }
    146154
    147155        this.propagate('close');
Note: See TracChangeset for help on using the changeset viewer.