Skip to content

Commit 1d1de7f

Browse files
committed
Dialog: If a show animation is provided, the post-show code dependent on the dialog being ready occur in a callback function passed to the show method. Fixed #4421, 4675 - Focus lost from dialog which uses show effect.
1 parent e4e5c29 commit 1d1de7f

File tree

1 file changed

+49
-38
lines changed

1 file changed

+49
-38
lines changed

ui/jquery.ui.dialog.js

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -282,50 +282,61 @@ $.widget("ui.dialog", {
282282
}
283283
self._size();
284284
self._position(options.position);
285-
uiDialog.show(options.show);
286-
self.moveToTop(true);
287-
288-
// prevent tabbing out of modal dialogs
289-
if (options.modal) {
290-
uiDialog.bind('keypress.ui-dialog', function(event) {
291-
if (event.keyCode !== $.ui.keyCode.TAB) {
292-
return;
293-
}
285+
286+
// Handle show animation
287+
var fShowCallback = function(event) {
288+
self.moveToTop(true);
294289

295-
var tabbables = $(':tabbable', this),
296-
first = tabbables.filter(':first'),
297-
last = tabbables.filter(':last');
290+
// prevent tabbing out of modal dialogs
291+
if (options.modal) {
292+
uiDialog.bind('keypress.ui-dialog', function(event) {
293+
if (event.keyCode !== $.ui.keyCode.TAB) {
294+
return;
295+
}
296+
297+
var tabbables = $(':tabbable', this),
298+
first = tabbables.filter(':first'),
299+
last = tabbables.filter(':last');
300+
301+
if (event.target === last[0] && !event.shiftKey) {
302+
first.focus(1);
303+
return false;
304+
} else if (event.target === first[0] && event.shiftKey) {
305+
last.focus(1);
306+
return false;
307+
}
308+
});
309+
}
298310

299-
if (event.target === last[0] && !event.shiftKey) {
300-
first.focus(1);
301-
return false;
302-
} else if (event.target === first[0] && event.shiftKey) {
303-
last.focus(1);
304-
return false;
305-
}
306-
});
307-
}
308-
309-
// set focus to the first tabbable element in the content area or the first button
310-
// if there are no tabbable elements, set focus on the dialog itself
311-
if (!options.focusSelector) {
312-
var arrTab = [],
313-
$tab;
311+
// set focus to the first tabbable element in the content area or the first button
312+
// if there are no tabbable elements, set focus on the dialog itself
313+
if (!options.focusSelector) {
314+
var arrTab = [],
315+
$tab;
316+
317+
arrTab.push(uiDialog.find('.ui-dialog-content :tabbable:not(' + options.focusFilter + '):first').filter(':not(.close)'));
318+
arrTab.push(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'));
319+
arrTab.push(uiDialog);
314320

315-
arrTab.push(uiDialog.find('.ui-dialog-content :tabbable:not(' + options.focusFilter + '):first').filter(':not(.close)'));
316-
arrTab.push(uiDialog.find('.ui-dialog-buttonpane :tabbable:first'));
317-
arrTab.push(uiDialog);
318-
319-
// Focus first populated selection
320-
for (var i = 0; i < arrTab.length; i++) {
321-
$tab = arrTab[i];
322-
if ($tab.length) {
323-
$tab.focus();
324-
break;
321+
// Focus first populated selection
322+
for (var i = 0; i < arrTab.length; i++) {
323+
$tab = arrTab[i];
324+
if ($tab.length) {
325+
$tab.focus();
326+
break;
327+
}
325328
}
329+
} else {
330+
uiDialog.find(options.focusSelector).focus();
326331
}
332+
};
333+
334+
if (options.show) {
335+
uiDialog.show(options.show, fShowCallback);
327336
} else {
328-
uiDialog.find(options.focusSelector).focus();
337+
uiDialog.show();
338+
339+
fShowCallback();
329340
}
330341

331342
self._trigger('open');

0 commit comments

Comments
 (0)