diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index e6156d82b0..61fd6a01a9 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -144,7 +144,10 @@ var Zotero_Lookup = new function () { ); if (newItems.length) { + // Send the focus to the item tree after the popup closes + ZoteroPane.lastFocusedElement = null; document.getElementById("zotero-lookup-panel").hidePopup(); + document.getElementById("item-tree-main-default").focus(); } return false; }; diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 51051909ee..1f251676b8 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -436,9 +436,10 @@ var ZoteroPane = new function() } function addFocusHandlers() { - // When a menupopup shows, hide the focus ring around the currently focused element + // When the item type menupopup from itemBoxshows, + // hide the focus ring around the currently focused element document.addEventListener("popupshowing", (e) => { - if (e.target.tagName == "menupopup") { + if (e.target.tagName == "menupopup" && e.target.parentNode.id == "item-type-menu") { document.activeElement.style.setProperty('--width-focus-border', '0'); document.activeElement.classList.add("hidden-focus"); } @@ -447,7 +448,7 @@ var ZoteroPane = new function() // When a panel popup hides, refocus the previous element // When a menupopup hides, stop hiding the focus-ring document.addEventListener("popuphiding", (e) => { - if (e.target.tagName == "panel" + if (ZoteroPane.lastFocusedElement && e.target.tagName == "panel" && document.activeElement && e.target.contains(document.activeElement)) { ZoteroPane.lastFocusedElement.focus(); }