From 1459ca210d03d366aee0bb0cd912a14ad0969d50 Mon Sep 17 00:00:00 2001 From: abaevbog Date: Tue, 15 Apr 2025 22:57:13 -0700 Subject: [PATCH] new collection dlg: fix menu keyboard nav on win (#5208) Fixed non-working selection of collections in the dropdown via keyboard on Windows. Fixes: #5202 --- chrome/content/zotero/newCollectionDialog.js | 21 +++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/newCollectionDialog.js b/chrome/content/zotero/newCollectionDialog.js index 7420564b50..d956642b82 100644 --- a/chrome/content/zotero/newCollectionDialog.js +++ b/chrome/content/zotero/newCollectionDialog.js @@ -48,17 +48,18 @@ var Zotero_New_Collection_Dialog = { _updateMenu() { let createInField = document.querySelector('#create-in'); let menupopup = createInField.firstElementChild; - let id = menupopup.id; - // Fascinatingly, clearing the children of the menupopup isn't enough here. - // We have to completely recreate it or it will no longer be willing to open. - menupopup.replaceWith(menupopup = document.createXULElement('menupopup')); - menupopup.id = id; + menupopup.replaceChildren(); let createdNode = Zotero.Utilities.Internal.createMenuForTarget( Zotero.Libraries.get(this._libraryID), menupopup, this._parentCollectionID ? 'C' + this._parentCollectionID : 'L' + this._libraryID, (event, libraryOrCollection) => { + // if a menu for a collection with children is clicked, close the entire menu, + // otherwise it oddly remains open + if (event.target.tagName == "menu") { + menupopup.hidePopup(); + } this._libraryID = libraryOrCollection.libraryID; if (libraryOrCollection.objectType === 'collection') { this._parentCollectionID = libraryOrCollection.id; @@ -66,7 +67,7 @@ var Zotero_New_Collection_Dialog = { else { this._parentCollectionID = null; } - this._updateMenu(); + this._updateSelectedCollectionLabel(); }, null ); @@ -75,7 +76,13 @@ var Zotero_New_Collection_Dialog = { createdNode.replaceWith(...createdNode.menupopup.children); } - let checkedItem = menupopup.querySelector('[checked="true"]'); + this._updateSelectedCollectionLabel(); + }, + + _updateSelectedCollectionLabel() { + let createInField = document.querySelector('#create-in'); + let selectedID = this._parentCollectionID ? 'C' + this._parentCollectionID : 'L' + this._libraryID; + let checkedItem = createInField.querySelector(`[value="${selectedID}"]`); createInField.setAttribute('label', checkedItem?.label || ''); createInField.image = checkedItem?.image; }