]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Honor preventDefault when managing focus 1265/head
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 10 Jun 2014 11:51:25 +0000 (13:51 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Tue, 10 Jun 2014 11:59:45 +0000 (13:59 +0200)
If event.isDefaultPrevented() is true, the focus management is
completely skipped, assuming the user manages focus manually.

Fixes #10103
Closes gh-1265

tests/unit/dialog/dialog_core.js
ui/dialog.js

index c97f9585b34b6cf29801ce336aa43df3fe9a6ded..d72fef7b5bf21a16cbeb8682965040620b4159ef 100644 (file)
@@ -41,7 +41,7 @@ test("widget method", function() {
 });
 
 asyncTest( "focus tabbable", function() {
-       expect( 6 );
+       expect( 8 );
        var element,
                options = {
                        buttons: [{
@@ -118,7 +118,30 @@ asyncTest( "focus tabbable", function() {
                setTimeout(function() {
                        equal( document.activeElement, element.parent()[ 0 ], "6. the dialog itself" );
                        element.remove();
-                       start();
+                       setTimeout( step7 );
+               });
+       }
+
+       function step7() {
+               element = $( "<div><input name='0'><input name='1' autofocus></div>" ).dialog({
+                       open: function() {
+                               var inputs = $( this ).find( "input" );
+                               inputs.last().keydown(function( event ) {
+                                       event.preventDefault();
+                                       inputs.first().focus();
+                               });
+                       }
+               });
+               setTimeout(function() {
+                       var inputs = element.find( "input" );
+                       equal( document.activeElement, inputs[ 1 ], "Focus starts on second input" );
+                       inputs.last().simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
+                       setTimeout(function() {
+                               equal( document.activeElement, inputs[ 0 ],
+                                       "Honor preventDefault, allowing custom focus management" );
+                               element.remove();
+                               start();
+                       }, 50 );
                });
        }
 
index 7998b042c46106cb000ba31bcb9547b454eecd5b..0ee94e4cf99a1abe1311b9e69eb4d7019717ce23 100644 (file)
@@ -334,7 +334,7 @@ return $.widget( "ui.dialog", {
                                }
 
                                // prevent tabbing out of dialogs
-                               if ( event.keyCode !== $.ui.keyCode.TAB ) {
+                               if ( event.keyCode !== $.ui.keyCode.TAB || event.isDefaultPrevented() ) {
                                        return;
                                }
                                var tabbables = this.uiDialog.find( ":tabbable" ),