Skip to content

Commit a0b8476

Browse files
committed
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 jquerygh-1264
1 parent c31d5f0 commit a0b8476

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

tests/unit/dialog/dialog_core.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,28 +140,30 @@ test( "#7960: resizable handles below modal overlays", function() {
140140
asyncTest( "Prevent tabbing out of dialogs", function() {
141141
expect( 3 );
142142

143-
var element = $( "<div><input><input></div>" ).dialog(),
144-
inputs = element.find( "input" ),
145-
widget = element.dialog( "widget" )[ 0 ];
143+
var element = $( "<div><input name='0'><input name='1'></div>" ).dialog(),
144+
inputs = element.find( "input" );
145+
146+
// Remove close button to test focus on just the two buttons
147+
element.dialog( "widget" ).find( ".ui-button").remove();
146148

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

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

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

158160
element.remove();
159161
setTimeout( start );
160162
}
161163

162-
inputs[1].focus();
164+
inputs[ 1 ].focus();
163165
setTimeout(function() {
164-
equal( document.activeElement, inputs[1], "Focus set on second input" );
166+
equal( document.activeElement, inputs[ 1 ], "Focus set on second input" );
165167
inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB });
166168

167169
setTimeout( checkTab );

ui/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ return $.widget( "ui.dialog", {
348348
event.preventDefault();
349349
} else if ( ( event.target === first[0] || event.target === this.uiDialog[0] ) && event.shiftKey ) {
350350
this._delay(function() {
351-
first.focus();
351+
last.focus();
352352
});
353353
event.preventDefault();
354354
}

0 commit comments

Comments
 (0)