diff --git a/chrome/content/zotero/elements/itemPaneSidenav.js b/chrome/content/zotero/elements/itemPaneSidenav.js index 8da724e7da..229b57f8a8 100644 --- a/chrome/content/zotero/elements/itemPaneSidenav.js +++ b/chrome/content/zotero/elements/itemPaneSidenav.js @@ -745,21 +745,25 @@ }); firstBtn.dispatchEvent(clickEvent); } - setTimeout(() => { - // If notes are visible, tab into them - if (this._contextNotesPaneVisible) { - Services.focus.moveFocus(window, this.contextNotesPane, Services.focus.MOVEFOCUS_FORWARD, 0); - } - // Tab into the pinned section if it exists - else if (this.pinnedPane) { - Services.focus.moveFocus(window, this.container.getEnabledPane(this.pinnedPane), - Services.focus.MOVEFOCUS_FORWARD, 0); - } - // Otherwise, focus the top-level scrollable itemPane - else { - this._container.querySelector(".zotero-view-item").focus(); - } - }); + // Otherwise, just click on the focused button + else if (event.target.classList.contains("btn")) { + event.preventDefault(); + event.target.click(); + } + + // If notes are visible, tab into them + if (this._contextNotesPaneVisible) { + Services.focus.moveFocus(window, this.contextNotesPane, Services.focus.MOVEFOCUS_FORWARD, 0); + } + // Tab into the pinned section if it exists + else if (this.pinnedPane) { + Services.focus.moveFocus(window, this.container.getEnabledPane(this.pinnedPane), + Services.focus.MOVEFOCUS_FORWARD, 0); + } + // Otherwise, focus the top-level scrollable itemPane + else { + this._container.querySelector(".zotero-view-item").focus(); + } } }; diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index 94b423e9e9..3862c76db5 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -779,6 +779,25 @@ class ReaderInstance { async setContextPaneOpen(open) { await this._initPromise; + + // There are two toggle-pane buttons: in the reader and in the sidenav. Closing/opening + // the context pane may display one and hide the other. If a focused toggle-pane btn is being hidden, + // try to focus the other toggle-pane btn so that focus is not just lost. + if (!open && this._window.document.activeElement.dataset.action == "toggle-pane") { + // Context pane collapsed when sidenav button is focused - try to focus btn in reader toolbar + setTimeout(() => { + this._iframeWindow.document.querySelector(".context-pane-toggle").focus({ focusVisible: true }); + }); + } + else if (open && this._iframeWindow.document.activeElement.classList.contains("context-pane-toggle")) { + // Context pane expanded when toggle-pane in reader toolbar is focused. + // Try to focus the sidenav button, if reader's button was hidden + setTimeout(() => { + if (this._iframeWindow.document.querySelector("context-pane-toggle")) return; + this._window.document.querySelector("#zotero-context-pane-sidenav .btn[data-action='toggle-pane']").focus({ focusVisible: true }); + }); + } + this._internalReader.setContextPaneOpen(open); }