new item focus handling tweaks

- properly re-focus previously focused item type menu in itemBox
- fix strange behavior of re-emerging item type menu popup caused by
itemBox.focusFirstField
- force the focus-ring to be around the itemType menu
This commit is contained in:
Bogdan Abaev 2024-01-12 12:59:43 -05:00 committed by Dan Stillman
parent b6d5a52417
commit 3338b4b285
2 changed files with 13 additions and 8 deletions

View file

@ -458,6 +458,9 @@
if (activeArea) { if (activeArea) {
this._selectField = activeArea.getAttribute("fieldname"); this._selectField = activeArea.getAttribute("fieldname");
} }
if (document.activeElement == this.itemTypeMenu) {
this._selectField = "item-type-menu";
}
this.refresh(); this.refresh();
break; break;
} }
@ -488,6 +491,12 @@
this.addItemTypeMenu(); this.addItemTypeMenu();
this.updateItemTypeMenuSelection(); this.updateItemTypeMenuSelection();
this.itemTypeMenu.disabled = !this.showTypeMenu; this.itemTypeMenu.disabled = !this.showTypeMenu;
// Re-focus item type menu if it was focused before refresh
if (this._selectField == "item-type-menu") {
Services.focus.setFocus(this.itemTypeMenu, Services.focus.FLAG_SHOWRING);
this._selectField = null;
this._lastTabIndex = null;
}
var fieldNames = []; var fieldNames = [];
// Manual field order // Manual field order
@ -2272,11 +2281,6 @@
}, this); }, this);
} }
focusFirstField() {
this._focusNextField(0);
}
focusField(fieldName) { focusField(fieldName) {
let field = this.querySelector(`[fieldname="${fieldName}"][ztabindex]`); let field = this.querySelector(`[fieldname="${fieldName}"][ztabindex]`);
if (!field) return false; if (!field) return false;

View file

@ -1236,13 +1236,14 @@ var ZoteroPane = new function()
itemBox.removeHandler('itemtypechange', handleTypeChange); itemBox.removeHandler('itemtypechange', handleTypeChange);
itemBox.itemTypeMenu.firstChild.removeEventListener('popuphiding', removeTypeChangeHandler); itemBox.itemTypeMenu.firstChild.removeEventListener('popuphiding', removeTypeChangeHandler);
// Focus the title field after menu closes // Focus the title field after menu closes
itemBox.focusFirstField(); let title = document.querySelector("#zotero-item-pane-header").querySelector("editable-text");
title.focus();
}; };
itemBox.addHandler('itemtypechange', handleTypeChange); itemBox.addHandler('itemtypechange', handleTypeChange);
itemBox.itemTypeMenu.firstChild.addEventListener('popuphiding', removeTypeChangeHandler); itemBox.itemTypeMenu.firstChild.addEventListener('popuphiding', removeTypeChangeHandler);
menu.focus(); Services.focus.setFocus(menu, Services.focus.FLAG_SHOWRING);
document.getElementById('zotero-editpane-item-box').itemTypeMenu.menupopup.openPopup(menu, "before_start", 0, 0); itemBox.itemTypeMenu.menupopup.openPopup(menu, "before_start", 0, 0);
}.bind(this)()); }.bind(this)());
break; break;
case 'newNote': case 'newNote':