Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Dialog: Fix shift-tab handling, focus the correct element
Copy-paste error introduced in df6110c

Updates the tabbing test to be more specific about which element should
have focus, instead of only checking if focus is within the dialog.

Ref #9646
Ref #10103
Closes gh-1264
  • Loading branch information
jzaefferer committed Jun 10, 2014
commit a0b84767a76098cdcc6375dfe28a7fee866bd395
16 changes: 9 additions & 7 deletions tests/unit/dialog/dialog_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,28 +140,30 @@ test( "#7960: resizable handles below modal overlays", function() {
asyncTest( "Prevent tabbing out of dialogs", function() {
expect( 3 );

var element = $( "<div><input><input></div>" ).dialog(),
inputs = element.find( "input" ),
widget = element.dialog( "widget" )[ 0 ];
var element = $( "<div><input name='0'><input name='1'></div>" ).dialog(),
inputs = element.find( "input" );

// Remove close button to test focus on just the two buttons
element.dialog( "widget" ).find( ".ui-button").remove();

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

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

function checkShiftTab() {
ok( $.contains( widget, document.activeElement ), "Shift-Tab key event moved focus within the modal" );
equal( document.activeElement, inputs[ 1 ], "Shift-Tab key event moved focus back to second input" );

element.remove();
setTimeout( start );
}

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

setTimeout( checkTab );
Expand Down
2 changes: 1 addition & 1 deletion ui/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ return $.widget( "ui.dialog", {
event.preventDefault();
} else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) {
this._delay(function() {
first.focus();
last.focus();
});
event.preventDefault();
}
Expand Down