Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Unified Diff: ui/webui/resources/js/cr/ui/node_utils.js

Issue 862403006: extensions: fix focus management for all dialogs (not just options). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@classList-fix
Patch Set: kalman@ review Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/extensions/extensions.js ('k') | ui/webui/resources/js/cr/ui/page_manager/page.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/cr/ui/node_utils.js
diff --git a/ui/webui/resources/js/cr/ui/node_utils.js b/ui/webui/resources/js/cr/ui/node_utils.js
index a380670e4f31d07968325abddf25797016aa8da7..21b0fb16dbc448f4ea4ffe6d5c5e38b91fc6040d 100644
--- a/ui/webui/resources/js/cr/ui/node_utils.js
+++ b/ui/webui/resources/js/cr/ui/node_utils.js
@@ -31,3 +31,22 @@ cr.ui.reverseButtonStrips = function(opt_root) {
buttonStrip.setAttribute('reversed', '');
}
};
+
+/**
+ * Finds a good place to set initial focus. Generally called when UI is shown.
+ * @param {!Element} root Where to start looking for focusable controls.
+ */
+cr.ui.setInitialFocus = function(root) {
+ // Do not change focus if any element in |root| is already focused.
+ if (root.contains(document.activeElement))
+ return;
+
+ var elements = root.querySelectorAll('input, list, select, textarea, button');
+ for (var i = 0; i < elements.length; i++) {
+ var element = elements[i];
+ element.focus();
+ // .focus() isn't guaranteed to work. Continue until it does.
+ if (document.activeElement == element)
+ return;
+ }
+};
« no previous file with comments | « chrome/browser/resources/extensions/extensions.js ('k') | ui/webui/resources/js/cr/ui/page_manager/page.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698