Bug 1363728 - Remove the search input focus after clicking outside of the search input
MozReview-Commit-ID: BODoCIDjgR8
--- 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);
+});