Bug 1363728 - Remove the search input focus after clicking outside of the search input draft
authorEvan Tseng <evan@tseng.io>
Wed, 10 May 2017 16:28:20 -0400 (2017-05-10)
changeset 575744 5925988cb53cdd2df486591d4af27f9f6d6f27b3
parent 570861 076a7a66096f9e8d102548397254be32eb26bc3d
child 628010 101daefd95dc44747de2084d9f7d6d68e51b3312
push id58157
push userbmo:evan@tseng.io
push dateWed, 10 May 2017 20:41:10 +0000 (2017-05-10)
bugs1363728
milestone55.0a1
Bug 1363728 - Remove the search input focus after clicking outside of the search input MozReview-Commit-ID: BODoCIDjgR8
browser/components/preferences/in-content/preferences.js
browser/components/preferences/in-content/tests/browser_search_within_preferences.js
--- a/browser/components/preferences/in-content/preferences.js
+++ b/browser/components/preferences/in-content/preferences.js
@@ -66,16 +66,19 @@ function init_all() {
   let categories = document.getElementById("categories");
   categories.addEventListener("select", event => gotoPref(event.target.value));
 
   document.documentElement.addEventListener("keydown", function(event) {
     if (event.keyCode == KeyEvent.DOM_VK_TAB) {
       categories.setAttribute("keyboard-navigation", "true");
     }
   });
+  document.documentElement.addEventListener("mousedown", function() {
+    this.focus();
+  });
   categories.addEventListener("mousedown", function() {
     this.removeAttribute("keyboard-navigation");
   });
 
   window.addEventListener("hashchange", onHashChange);
   gotoPref();
 
   init_dynamic_padding();
--- a/browser/components/preferences/in-content/tests/browser_search_within_preferences.js
+++ b/browser/components/preferences/in-content/tests/browser_search_within_preferences.js
@@ -166,8 +166,34 @@ add_task(function*() {
   searchInput.value = "";
   searchInput.doCommand()
 
   // Checks if back to normal
   is_element_visible(generalPane, "Should be in generalPane");
 
   yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
 });
+
+/**
+ * Test for pressing enter on search field after doing search
+ */
+add_task(function*() {
+  yield openPreferencesViaOpenPreferencesAPI("paneGeneral", {leaveOpen: true});
+
+  // Performs search
+  let doc = gBrowser.contentDocument;
+  let searchInput = doc.getElementById("searchInput");
+  searchInput.focus();
+  searchInput.value = "password";
+  searchInput.doCommand();
+  is(searchInput.getAttribute("focused"), "true",
+    "Search input should be the active element before pressing Return");
+  is(doc.activeElement, doc.getAnonymousNodes(searchInput)[0].querySelector("input"),
+    "Search input should be the active element before pressing Return");
+
+  doc.getElementById("passwordsGroup").click();
+  is(searchInput.getAttribute("focused"), "",
+    "Search input should not be focused after pressing Return");
+  isnot(doc.activeElement, doc.getAnonymousNodes(searchInput)[0].querySelector("input"),
+    "Search input should not be focused after pressing Return");
+
+  yield BrowserTestUtils.removeTab(gBrowser.selectedTab);
+});