Skip to content

Commit 96e5c24

Browse files
committed
Dialog: Tabbing out of a modal dialog was possible because keypress doesn't fire for tabs everywhere, switched to keyup. Added Unit Test - Caught by @DomenicDenicola - Fixes #3123 - Tabbing stops in modal dialog
1 parent fb57cc8 commit 96e5c24

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

tests/unit/dialog/dialog_tickets.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,36 @@
33
*/
44
(function($) {
55

6-
module("dialog: tickets");
6+
module( "dialog: tickets" );
7+
8+
asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
9+
expect( 3 );
10+
11+
var el = $( "<div><input id='t3123-first'><input id='t3123-last'></div>" ).dialog({ modal: true }),
12+
inputs = el.find( "input" ),
13+
widget = el.dialog( "widget" );
14+
15+
inputs.eq( 1 ).focus();
16+
equal( document.activeElement, inputs[1], "Focus set on second input" );
17+
inputs.eq( 1 ).simulate( "keyup", { keyCode: $.ui.keyCode.TAB });
18+
19+
setTimeout( checkTab, 2 );
20+
21+
function checkTab() {
22+
ok( $.contains( widget, document.activeElement ), "Tab key event moved focus within the modal" );
23+
24+
// check shift tab
25+
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true });
26+
setTimeout( checkShiftTab, 2 );
27+
}
28+
29+
function checkShiftTab() {
30+
ok( $.contains( widget, document.activeElement ), "Shift-Tab key event moved focus within the modal" );
31+
32+
el.remove();
33+
start();
34+
}
35+
});
736

837
test("#4826: setting resizable false toggles resizable on dialog", function() {
938
expect(6);

ui/jquery.ui.dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ $.widget("ui.dialog", {
293293

294294
// prevent tabbing out of modal dialogs
295295
if ( options.modal ) {
296-
uiDialog.bind( "keypress.ui-dialog", function( event ) {
296+
uiDialog.bind( "keyup.ui-dialog", function( event ) {
297297
if ( event.keyCode !== $.ui.keyCode.TAB ) {
298298
return;
299299
}

0 commit comments

Comments
 (0)