minor focus tweaks

- after an item is added via "Add item by identifier" panel, end
focus to that item in itemTree.
- restored default behavior when the focus remains visible around an
element when all menupopups open, except for the item type menu in itemBox.
- opening item type menu will still hide the focus-ring
This commit is contained in:
abaevbog 2024-01-24 03:05:14 -05:00 committed by Dan Stillman
parent ed8e3f142b
commit 620b35ab78
2 changed files with 7 additions and 3 deletions

View file

@ -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;
};

View file

@ -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();
}