Skip to content

Commit

Permalink
Dialog: Selecting the first tabbable element using a native Array ins…
Browse files Browse the repository at this point in the history
…tead 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.
  • Loading branch information
ajcrews committed Jun 24, 2010
1 parent 965dddd commit 74157f8
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions ui/jquery.ui.dialog.js
Expand Up @@ -306,12 +306,30 @@ $.widget("ui.dialog", {

// set focus to the first tabbable element in the content area or the first button
// if there are no tabbable elements, set focus on the dialog itself
$([])
.add(uiDialog.find('.ui-dialog-content :tabbable:first'))
.add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'))
.add(uiDialog)
.filter(':first')
.focus();
var fSetFocus = function() {
var arrTab = [],
$tab;

arrTab.push(uiDialog.find('.ui-dialog-content :tabbable:first'));
arrTab.push(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'));
arrTab.push(uiDialog);

// Focus first populated selection
for (var i = 0; i < arrTab.length; i++) {
$tab = arrTab[i];
if ($tab.length) {
$tab.focus();
break;
}
}
};

// TODO: Find a proper fix for Firefox 3.6.x
if ($.browser.mozilla) {
window.setTimeout(fSetFocus, 0)
} else {
fSetFocus();
}

self._trigger('open');
self._isOpen = true;
Expand Down

1 comment on commit 74157f8

@ajcrews
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.