Skip to content

Commit 60856ea

Browse files
committed
Dialog: Giving the content area and button pane priority over the title bar for which element should gain focus on open.
1 parent 0ce1fa2 commit 60856ea

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

ui/ui.dialog.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,18 @@ $.widget("ui.dialog", {
207207
open: function() {
208208
if (this._isOpen) { return; }
209209

210-
this.overlay = this.options.modal ? new $.ui.dialog.overlay(this) : null;
211-
(this.uiDialog.next().length && this.uiDialog.appendTo('body'));
210+
var options = this.options,
211+
uiDialog = this.uiDialog;
212+
213+
this.overlay = options.modal ? new $.ui.dialog.overlay(this) : null;
214+
(uiDialog.next().length && uiDialog.appendTo('body'));
212215
this._size();
213-
this._position(this.options.position);
214-
this.uiDialog.show(this.options.show);
216+
this._position(options.position);
217+
uiDialog.show(options.show);
215218
this.moveToTop(true);
216219

217220
// prevent tabbing out of modal dialogs
218-
(this.options.modal && this.uiDialog.bind('keypress.ui-dialog', function(event) {
221+
(options.modal && uiDialog.bind('keypress.ui-dialog', function(event) {
219222
if (event.keyCode != $.ui.keyCode.TAB) {
220223
return;
221224
}
@@ -235,7 +238,17 @@ $.widget("ui.dialog", {
235238
}
236239
}));
237240

238-
this.uiDialog.find(':tabbable:first').focus();
241+
// set focus to the first tabbable element in:
242+
// - content area
243+
// - button pane
244+
// - title bar
245+
$([])
246+
.add(uiDialog.find('.ui-dialog-content :tabbable:first'))
247+
.add(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'))
248+
.add(uiDialog.find('.ui-dialog-titlebar :tabbable:first'))
249+
.filter(':first')
250+
.focus();
251+
239252
this._trigger('open');
240253
this._isOpen = true;
241254
},

0 commit comments

Comments
 (0)