Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 39aea2b

Browse files
author
Gabriel Schulhof
committed
[popup] Restrict focus to elements inside the popup -- Fixes #5130
Caveat: This kind of focus restriction can still be circumvented using FF's type-to-search feature
1 parent 823e54a commit 39aea2b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

js/widgets/popup.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,18 @@ define( [ "jquery",
143143
}
144144
},
145145

146+
// When the popup is open, attempting to focus on an element that is not a child of the popup will redirect focus to the popup
147+
_handleDocumentFocusIn: function( e ) {
148+
if ( this._isOpen &&
149+
e.target !== this._ui.container[ 0 ] &&
150+
0 === $( e.target ).parents().filter( this._ui.container[ 0 ] ).length ) {
151+
this._ui.container.focus();
152+
e.preventDefault();
153+
e.stopImmediatePropagation();
154+
return false;
155+
}
156+
},
157+
146158
_create: function() {
147159
var ui = {
148160
screen: $( "<div class='ui-screen-hidden ui-popup-screen'></div>" ),
@@ -208,6 +220,9 @@ define( [ "jquery",
208220
resize: $.proxy( this, "_handleWindowResize" ),
209221
keyup: $.proxy( this, "_handleWindowKeyUp" )
210222
});
223+
this._on( $( document ), {
224+
focusin: $.proxy( this, "_handleDocumentFocusIn" )
225+
});
211226
},
212227

213228
_applyTheme: function( dst, theme, prefix ) {

0 commit comments

Comments
 (0)