1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Ensure focus returns to the right element after dialogs shown

This commit is contained in:
Nick O'Leary 2019-06-14 10:57:12 +01:00
parent ae2162beaf
commit bb67049d90
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
2 changed files with 12 additions and 0 deletions

View File

@ -23,6 +23,7 @@ RED.actionList = (function() {
var visible = false; var visible = false;
var filterTerm = ""; var filterTerm = "";
var previousActiveElement;
function ensureSelectedIsVisible() { function ensureSelectedIsVisible() {
var selectedEntry = searchResults.find("li.selected"); var selectedEntry = searchResults.find("li.selected");
@ -135,6 +136,7 @@ RED.actionList = (function() {
return; return;
} }
if (!visible) { if (!visible) {
previousActiveElement = document.activeElement;
RED.keyboard.add("*","escape",function(){hide()}); RED.keyboard.add("*","escape",function(){hide()});
$("#red-ui-header-shade").show(); $("#red-ui-header-shade").show();
$("#red-ui-editor-shade").show(); $("#red-ui-editor-shade").show();
@ -177,6 +179,10 @@ RED.actionList = (function() {
}); });
} }
RED.events.emit("actionList:close"); RED.events.emit("actionList:close");
if (previousActiveElement) {
$(previousActiveElement).trigger("focus");
previousActiveElement = null;
}
} }
} }

View File

@ -25,6 +25,7 @@ RED.search = (function() {
var index = {}; var index = {};
var keys = []; var keys = [];
var results = []; var results = [];
var previousActiveElement;
function indexProperty(node,label,property) { function indexProperty(node,label,property) {
@ -253,6 +254,7 @@ RED.search = (function() {
return; return;
} }
if (!visible) { if (!visible) {
previousActiveElement = document.activeElement;
RED.keyboard.add("*","escape",function(){hide()}); RED.keyboard.add("*","escape",function(){hide()});
$("#red-ui-header-shade").show(); $("#red-ui-header-shade").show();
$("#red-ui-editor-shade").show(); $("#red-ui-editor-shade").show();
@ -286,6 +288,10 @@ RED.search = (function() {
}); });
} }
RED.events.emit("search:close"); RED.events.emit("search:close");
if (previousActiveElement) {
$(previousActiveElement).trigger("focus");
previousActiveElement = null;
}
} }
} }