Skip to content

Commit 74157f8

Browse files
committed
Dialog: Selecting the first tabbable element using a native Array instead of the jQuery "add" method, since "add" always returns in document order as of jQuery 1.4. Fixed #5767 - On open, the first tabbable element inside the dialog was never being focused in favor of the dialog container.
1 parent 965dddd commit 74157f8

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

ui/jquery.ui.dialog.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,12 +306,30 @@ $.widget("ui.dialog", {
306306

307307
// set focus to the first tabbable element in the content area or the first button
308308
// if there are no tabbable elements, set focus on the dialog itself
309-
$([])
310-
.add(uiDialog.find('.ui-dialog-content :tabbable:first'))
311-
.add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'))
312-
.add(uiDialog)
313-
.filter(':first')
314-
.focus();
309+
var fSetFocus = function() {
310+
var arrTab = [],
311+
$tab;
312+
313+
arrTab.push(uiDialog.find('.ui-dialog-content :tabbable:first'));
314+
arrTab.push(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'));
315+
arrTab.push(uiDialog);
316+
317+
// Focus first populated selection
318+
for (var i = 0; i < arrTab.length; i++) {
319+
$tab = arrTab[i];
320+
if ($tab.length) {
321+
$tab.focus();
322+
break;
323+
}
324+
}
325+
};
326+
327+
// TODO: Find a proper fix for Firefox 3.6.x
328+
if ($.browser.mozilla) {
329+
window.setTimeout(fSetFocus, 0)
330+
} else {
331+
fSetFocus();
332+
}
315333

316334
self._trigger('open');
317335
self._isOpen = true;

0 commit comments

Comments
 (0)