Skip to content

Commit

Permalink
Fixe focus first element issues
Browse files Browse the repository at this point in the history
1. Moved to the afterOpen event.
2. Allowed focusing close button.

Resolves #943
  • Loading branch information
danieliser committed Feb 21, 2021
1 parent 0fd34d4 commit c2be371
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions assets/js/src/site/plugins/pum-accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,17 @@ var PUM_Accessibility;
}
},
setFocusToFirstItem: function() {
// set focus to first focusable item
currentModal
var $firstEl = currentModal
.find( '.pum-container *' )
.filter( focusableElementsString )
.filter( ':visible' )
.filter( ':not(.pum-close)' )
.first()
.focus();
},
};
//.filter( ':not(.pum-close)' )
.first();

$( document )
.on( 'pumInit', selector, function() {
PUM.getPopup( this )
.find( '[tabindex]' )
.each( function() {
var $this = $( this );
$this
.data( 'tabindex', $this.attr( 'tabindex' ) )
.prop( 'tabindex', '0' );
} );
} )
.on( 'pumBeforeOpen', selector, function() {
// set focus to first focusable item
$firstEl.focus();
},
initiateFocusLock: function() {
var $popup = PUM.getPopup( this ),
$focused = $( ':focus' );

Expand Down Expand Up @@ -109,8 +97,22 @@ var PUM_Accessibility;

// Accessibility: Focus on the modal.
PUM_Accessibility.setFocusToFirstItem();
},
};

$( document )
.on( 'pumInit', selector, function() {
PUM.getPopup( this )
.find( '[tabindex]' )
.each( function() {
var $this = $( this );
$this
.data( 'tabindex', $this.attr( 'tabindex' ) )
.prop( 'tabindex', '0' );
} );
} )
.on( 'pumAfterOpen', selector, function() {} )
.on( 'pumBeforeOpen', selector, function() {} )
.on( 'pumAfterOpen', selector, PUM_Accessibility.initiateFocusLock )
.on( 'pumBeforeClose', selector, function() {} )
.on( 'pumAfterClose', selector, function() {
var $popup = PUM.getPopup( this );
Expand Down

0 comments on commit c2be371

Please sign in to comment.