Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 9bbfcea

Browse files
author
Narciso Jaramillo
committed
Merge pull request #7677 from adobe/tom/issue-7598
Fix 7598: showModalDialogUsingTemplate doesn't blur current editor
2 parents f58e3fd + 921d1c7 commit 9bbfcea

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/widgets/Dialogs.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,11 @@ define(function (require, exports, module) {
272272

273273
$("body").append("<div class='modal-wrapper'><div class='modal-inner-wrapper'></div></div>");
274274

275-
var result = $.Deferred(),
276-
promise = result.promise(),
277-
$dlg = $(template)
275+
var result = new $.Deferred(),
276+
promise = result.promise(),
277+
$dlg = $(template)
278278
.addClass("instance")
279+
.prop("tabindex", "-1")
279280
.appendTo(".modal-inner-wrapper:last");
280281

281282
// Don't allow dialog to exceed viewport size
@@ -311,11 +312,17 @@ define(function (require, exports, module) {
311312
//Remove wrapper
312313
$(".modal-wrapper:last").remove();
313314
}).one("shown", function () {
314-
// Set focus to the default button
315-
var primaryBtn = $dlg.find(".primary");
316-
317-
if (primaryBtn) {
318-
primaryBtn.focus();
315+
var $primaryBtn = $dlg.find(".primary:enabled"),
316+
$otherBtn = $dlg.find(".modal-footer .dialog-button:enabled:eq(0)");
317+
318+
// Set focus to the primary button, to any other button, or to the dialog depending
319+
// if there are buttons
320+
if ($primaryBtn.length) {
321+
$primaryBtn.focus();
322+
} else if ($otherBtn.length) {
323+
$otherBtn.focus();
324+
} else {
325+
$dlg.focus();
319326
}
320327

321328
// Push our global keydown handler onto the global stack of handlers.

0 commit comments

Comments
 (0)