]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Tabbing out of a modal dialog was possible because keypress doesn't fire...
authorCorey Frang <gnarf@gnarf.net>
Fri, 19 Aug 2011 11:07:47 +0000 (06:07 -0500)
committerCorey Frang <gnarf@gnarf.net>
Fri, 19 Aug 2011 11:07:47 +0000 (06:07 -0500)
(cherry picked from commit 96e5c241e1b26224c53738b590e07290db7a3e54)

tests/unit/dialog/dialog_tickets.js
ui/jquery.ui.dialog.js

index def2452dedfc5bfb30915b57f55d7626d6847e61..acfddab4352d4dd5934e60d528ef76671c630847 100644 (file)
@@ -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 });
+               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);
index 32846d3fd73f8f79380af1429a5de711ce96f326..3d11cf948c361c85066048e57ba916633693bf74 100644 (file)
@@ -329,9 +329,9 @@ $.widget("ui.dialog", {
                self.moveToTop(true);
 
                // prevent tabbing out of modal dialogs
-               if (options.modal) {
-                       uiDialog.bind('keypress.ui-dialog', function(event) {
-                               if (event.keyCode !== $.ui.keyCode.TAB) {
+               if ( options.modal ) {
+                       uiDialog.bind( "keyup.ui-dialog", function( event ) {
+                               if ( event.keyCode !== $.ui.keyCode.TAB ) {
                                        return;
                                }