Bug 1237350 - don't steal focus for the search box if another piece of non-button/non-input UI has focus, r?jaws,giorgios
--- a/browser/base/content/abouthome/aboutHome.js
+++ b/browser/base/content/abouthome/aboutHome.js
@@ -51,19 +51,31 @@ window.addEventListener("pageshow", func
});
window.addEventListener("pagehide", function() {
window.gObserver.disconnect();
window.removeEventListener("resize", fitToWidth);
});
window.addEventListener("keypress", ev => {
- // focus the search-box on keypress
- if (document.activeElement.id == "searchText") // unless already focussed
+ if (ev.defaultPrevented) {
return;
+ }
+
+ // don't focus the search-box on keypress if something other than the
+ // body or document element has focus - don't want to steal input from other elements
+ // Make an exception for <a> and <button> elements (and input[type=button|submit])
+ // which don't usefully take keypresses anyway.
+ // (except space, which is handled below)
+ if (document.activeElement && document.activeElement != document.body &&
+ document.activeElement != document.documentElement &&
+ !["a", "button"].includes(document.activeElement.localName) &&
+ !document.activeElement.matches("input:-moz-any([type=button],[type=submit])")) {
+ return;
+ }
let modifiers = ev.ctrlKey + ev.altKey + ev.metaKey;
// ignore Ctrl/Cmd/Alt, but not Shift
// also ignore Tab, Insert, PageUp, etc., and Space
if (modifiers != 0 || ev.charCode == 0 || ev.charCode == 32)
return;
searchText.focus();