Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/widgets/Dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,11 @@ define(function (require, exports, module) {

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

var result = $.Deferred(),
promise = result.promise(),
$dlg = $(template)
var result = new $.Deferred(),
promise = result.promise(),
$dlg = $(template)
.addClass("instance")
.prop("tabindex", "-1")
.appendTo(".modal-inner-wrapper:last");

// Don't allow dialog to exceed viewport size
Expand Down Expand Up @@ -302,11 +303,17 @@ define(function (require, exports, module) {
//Remove wrapper
$(".modal-wrapper:last").remove();
}).one("shown", function () {
// Set focus to the default button
var primaryBtn = $dlg.find(".primary");

if (primaryBtn) {
primaryBtn.focus();
var $primaryBtn = $dlg.find(".primary:enabled"),
$otherBtn = $dlg.find(".modal-footer .dialog-button:enabled:eq(0)");

// Set focus to the primary button, to any other button, or to the dialog depending
// if there are buttons
if ($primaryBtn.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We not try and set focus to the element with the lowest tabindex first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure how that will work. But maybe we can first focus any input.

$primaryBtn.focus();
} else if ($otherBtn.length) {
$otherBtn.focus();
} else {
$dlg.focus();
}

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