Commit 88e111c6 authored by henry's avatar henry Committed by Richard Pospesel
Browse files

fixup! Bug 41454: Move focus after calling openPreferences for a sub-category.

Bug 42167: Make the auto-focus more reliable.

No longer use the setTimeout to wait a loop, but instead wait for the
"load" event.
parent fae8c72e
Loading
Loading
Loading
Loading
+14 −5
Changes for browser/components/preferences/preferences.js: 14 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -482,14 +482,23 @@ async function scrollAndHighlight(subcategory, category) {

  // 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 bug 1799153.
  // See tor-browser#41454 and mozilla bug 1799153.
  const doFocus = () => {
    element.setAttribute("tabindex", "-1");
  // The element is not always immediately focusable, so we wait until the next
  // loop.
  setTimeout(() => {
    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 });
  }

  scrollContentTo(header);
  element.classList.add("spotlight");