Skip to content
Permalink
Browse files

Dialog: Tabbing out of a modal dialog was possible because keypress d…

…oesn't fire for tabs everywhere, switched to keyup. Added Unit Test - Caught by @DomenicDenicola - Fixes #3123 - Tabbing stops in modal dialog
  • Loading branch information...
gnarf committed Aug 19, 2011
1 parent fb57cc8 commit 96e5c241e1b26224c53738b590e07290db7a3e54
Showing with 31 additions and 2 deletions.
  1. +30 −1 tests/unit/dialog/dialog_tickets.js
  2. +1 −1 ui/jquery.ui.dialog.js
@@ -3,7 +3,36 @@
*/
(function($) {

module("dialog: tickets");
module( "dialog: tickets" );

asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
expect( 3 );

var el = $( "<div><input id='t3123-first'><input id='t3123-last'></div>" ).dialog({ modal: true }),
inputs = el.find( "input" ),
widget = el.dialog( "widget" );

inputs.eq( 1 ).focus();
equal( document.activeElement, inputs[1], "Focus set on second input" );
inputs.eq( 1 ).simulate( "keyup", { keyCode: $.ui.keyCode.TAB });

setTimeout( checkTab, 2 );

function checkTab() {
ok( $.contains( widget, document.activeElement ), "Tab key event moved focus within the modal" );

// check shift tab
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true });

This comment has been minimized.

Copy link
@jzaefferer

jzaefferer Aug 19, 2011

Member

Is this supposed to use keydown, not keyup?

This comment has been minimized.

Copy link
@gnarf

gnarf Aug 19, 2011

Author Member

Shit, I missed one, its supposed to be a keyup - sorry - will push a quick fix for it soon

setTimeout( checkShiftTab, 2 );
}

function checkShiftTab() {
ok( $.contains( widget, document.activeElement ), "Shift-Tab key event moved focus within the modal" );

el.remove();
start();
}
});

test("#4826: setting resizable false toggles resizable on dialog", function() {
expect(6);
@@ -293,7 +293,7 @@ $.widget("ui.dialog", {

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

1 comment on commit 96e5c24

@domenic

This comment has been minimized.

Copy link

commented on 96e5c24 Aug 20, 2011

keyup does not work; please see my comment in the issue.

Please sign in to comment.
You can’t perform that action at this time.