commit f9bd4266a910fa5da84037801418efc82a7160a6
parent a024818a1fce3720650f18af2947a25068f64cb5
Author: Moritz Beier <mbeier@mozilla.com>
Date: Tue, 11 Nov 2025 20:02:19 +0000
Bug 1998443 - CMD+K doesn't work with the new searchbar. r=dao,search-reviewers,Standard8
Differential Revision: https://phabricator.services.mozilla.com/D271749
Diffstat:
6 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/browser/components/customizableui/test/CustomizableUITestUtils.sys.mjs b/browser/components/customizableui/test/CustomizableUITestUtils.sys.mjs
@@ -131,7 +131,11 @@ export class CustomizableUITestUtils {
return !navbar.overflowable.isHandlingOverflow();
});
- let searchbar = this.window.document.getElementById("searchbar");
+ let searchbar = this.window.document.getElementById(
+ Services.prefs.getBoolPref("browser.search.widget.new")
+ ? "searchbar-new"
+ : "searchbar"
+ );
if (!searchbar) {
throw new Error("The search bar should exist.");
}
diff --git a/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js b/browser/components/customizableui/test/browser_901207_searchbar_in_panel.js
@@ -7,10 +7,14 @@
logActiveElement();
async function waitForSearchBarFocus() {
- let searchbar = document.getElementById("searchbar");
+ let searchbar = document.getElementById(
+ Services.prefs.getBoolPref("browser.search.widget.new")
+ ? "searchbar-new"
+ : "searchbar"
+ );
await TestUtils.waitForCondition(function () {
logActiveElement();
- return document.activeElement === searchbar.textbox;
+ return document.activeElement === searchbar.inputField;
});
}
diff --git a/browser/components/search/SearchUIUtils.sys.mjs b/browser/components/search/SearchUIUtils.sys.mjs
@@ -7,7 +7,8 @@
*/
/**
- * @import {SearchUtils} from "moz-src:///toolkit/components/search/SearchUtils.sys.mjs"
+ * @import { SearchUtils } from "moz-src:///toolkit/components/search/SearchUtils.sys.mjs"
+ * @import { UrlbarInput } from "chrome://browser/content/urlbar/UrlbarInput.mjs";
*/
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
@@ -310,21 +311,30 @@ export var SearchUIUtils = {
return;
}
- let focusUrlBarIfSearchFieldIsNotActive = function (aSearchBar) {
- if (!aSearchBar || window.document.activeElement != aSearchBar.textbox) {
+ /** @type {(searchBar: MozSearchbar | UrlbarInput) => void} */
+ let focusUrlBarIfSearchFieldIsNotActive = function (searchBar) {
+ if (!searchBar || window.document.activeElement != searchBar.inputField) {
// Limit the results to search suggestions, like the search bar.
window.gURLBar.searchModeShortcut();
}
};
- let searchBar = /** @type {MozSearchbar} */ (
- window.document.getElementById("searchbar")
+ let searchBar = /** @type {MozSearchbar | UrlbarInput} */ (
+ window.document.getElementById(
+ Services.prefs.getBoolPref("browser.search.widget.new")
+ ? "searchbar-new"
+ : "searchbar"
+ )
);
let placement =
lazy.CustomizableUI.getPlacementOfWidget("search-container");
let focusSearchBar = () => {
- searchBar = /** @type {MozSearchbar} */ (
- window.document.getElementById("searchbar")
+ searchBar = /** @type {MozSearchbar | UrlbarInput} */ (
+ window.document.getElementById(
+ Services.prefs.getBoolPref("browser.search.widget.new")
+ ? "searchbar-new"
+ : "searchbar"
+ )
);
searchBar.select();
focusUrlBarIfSearchFieldIsNotActive(searchBar);
diff --git a/browser/components/search/content/searchbar.js b/browser/components/search/content/searchbar.js
@@ -207,6 +207,13 @@
return this._textbox;
}
+ /**
+ * Textbox alias for API compatibility with UrlbarInput.
+ */
+ get inputField() {
+ return this.textbox;
+ }
+
set value(val) {
this._textbox.value = val;
}
diff --git a/browser/components/search/test/browser/browser_webSearch.js b/browser/components/search/test/browser/browser_webSearch.js
@@ -53,12 +53,15 @@ add_task(async function test_urlbar() {
add_task(async function test_searchBar() {
let searchBar = await gCUITestUtils.addSearchBar();
- let focusPromise = BrowserTestUtils.waitForEvent(searchBar.textbox, "focus");
+ let focusPromise = BrowserTestUtils.waitForEvent(
+ searchBar.inputField,
+ "focus"
+ );
EventUtils.synthesizeKey("k", { accelKey: true });
await focusPromise;
Assert.equal(
document.activeElement,
- searchBar.textbox,
+ searchBar.inputField,
"Focused the search bar."
);
diff --git a/browser/components/search/types/searchbar.d.ts b/browser/components/search/types/searchbar.d.ts
@@ -2,4 +2,5 @@
// searchbar becomes a exportable module.
interface MozSearchbar extends MozXULElement {
select(): void;
+ get inputField(): HTMLInputElement;
}