Skip to content

Commit

Permalink
methods to tab in/out of the reader
Browse files Browse the repository at this point in the history
- added onToolbarShiftTab, onIframeTab methods that to focus manager
that are called on shift-tab from the first group/tab from the last group
- added focusToolBar method to focus the first button of the toolbar
within the reader
  • Loading branch information
abaevbog committed Feb 12, 2024
1 parent 39e92a1 commit cedca6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/common/focus-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export class FocusManager {
constructor(options) {
this._reader = options.reader;
this._onDeselectAnnotations = options.onDeselectAnnotations;
// Methods to move focus to elements outside of the reader
this._onToolbarShiftTab = options.onToolbarShiftTab;
this._onIframeTab = options.onIframeTab;
window.addEventListener('focusin', this._handleFocus.bind(this));
window.addEventListener('pointerdown', this._handlePointerDown.bind(this));
window.addEventListener('keydown', this._handleKeyDown.bind(this), true);
Expand All @@ -30,6 +33,11 @@ export class FocusManager {
}
}

// Focus the first button from the toolbar
focusToolbar() {
document.querySelector(".toolbar .start .toolbar-button").focus();
}

_initFirefoxActivePseudoClassFix() {
// Work around :active pseudo class being prevented by event.preventDefault() on Firefox.
window.addEventListener('pointerdown', (event) => {
Expand Down Expand Up @@ -135,7 +143,19 @@ export class FocusManager {

let groupIndex = groups.findIndex(x => x === group);

if (groupIndex === -1 || groupIndex === groups.length - 1) {
if (groupIndex === groups.length - 1) {
if (reverse) {
// Shift-tab from the first group (toolbar)
this._onToolbarShiftTab();
}
else {
// Tab from the last group (reader iframe)
this._onIframeTab();
}
return;
}

if (groupIndex === -1) {
groupIndex = 0;
}
else {
Expand Down
12 changes: 12 additions & 0 deletions src/common/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Reader {
this._onRotatePages = options.onRotatePages;
this._onDeletePages = options.onDeletePages;
this._onToggleContextPane = options.onToggleContextPane;
this._onToolbarShiftTab = options.onToolbarShiftTab;
this._onIframeTab = options.onIframeTab;
// Only used on Zotero client, sets text/plain and text/html values from Note Markdown and Note HTML translators
this._onSetDataTransferAnnotations = options.onSetDataTransferAnnotations;

Expand Down Expand Up @@ -190,6 +192,12 @@ class Reader {
reader: this,
onDeselectAnnotations: () => {
this.setSelectedAnnotations([]);
},
onToolbarShiftTab: () => {
this._onToolbarShiftTab();
},
onIframeTab: () => {
this._onIframeTab();
}
});

Expand Down Expand Up @@ -1105,6 +1113,10 @@ class Reader {
this._focusManager.restoreFocus();
}

focusToolbar() {
this._focusManager.focusToolbar();
}

freeze() {
this._updateState({ freeze: true });
}
Expand Down

0 comments on commit cedca6b

Please sign in to comment.