commit 2fd2434c01c465dd6de177392e7882a12d3af59a
parent d85f986128a5a953f322a4ebd88e0519dd0206db
Author: Henry Wilkes <henry@torproject.org>
Date: Tue, 15 Nov 2022 11:48:04 +0000
BB 41454: Move focus after calling openPreferences for a sub-category.
Temporary fix until mozilla bug 1799153 gets a patch upstream.
Diffstat:
1 file changed, 20 insertions(+), 0 deletions(-)
diff --git a/browser/components/preferences/preferences.js b/browser/components/preferences/preferences.js
@@ -630,6 +630,26 @@ function scrollAndHighlight(subcategory) {
return;
}
+ // We assign a tabindex=-1 to the element so that we can focus it. This allows
+ // us to move screen reader's focus to an arbitrary position on the page.
+ // See tor-browser#41454 and mozilla bug 1799153.
+ const doFocus = () => {
+ element.setAttribute("tabindex", "-1");
+ Services.focus.setFocus(element, Services.focus.FLAG_NOSCROLL);
+ // Immediately remove again now that it has focus.
+ element.removeAttribute("tabindex");
+ };
+ // The element is not always immediately focusable, so we wait until document
+ // load.
+ if (document.readyState === "complete") {
+ doFocus();
+ } else {
+ // Wait until document load to move focus.
+ // NOTE: This should be called after DOMContentLoaded, where the searchInput
+ // is focused.
+ window.addEventListener("load", doFocus, { once: true });
+ }
+
element.scrollIntoView({
behavior: "smooth",
block: "center",