Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
import queryString from 'query-string';
import { hot } from 'react-hot-loader';
import { getFirstFocusable } from '@folio/stripes-components/util/getFocusableElements';
Copy link
Member

@zburke zburke Oct 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import getFirstFocusable directly from @folio/stripes/components; you don't have to reach in and get it by private path.


import { AppContextMenu, Route, Switch, IfPermission } from '@folio/stripes/core';
import {
Expand All @@ -26,6 +27,18 @@ import {
NoteEditPage
} from './views';
import KeyboardShortcutsModal from './components/KeyboardShortcutsModal';
import { PatronBlockMessage } from './components/PatronBlock';

const modifiedCommands = [...commands,
{
name: 'nextPane',
shortcut: 'shift + pagedown'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, no pagedown or pageup keys on a MacOS laptop keyboard. I know I know, WIP, POC, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for re-iterating this on this rather ancient POC... For persistence of the conversation, Does fn up/down arrow perform the same function/key as pageup/down? can you shift + fn + arrow on a mac?

},
{
name: 'previousPane',
shortcut: 'shift + pageup'
},
];

class UsersRouting extends React.Component {
static propTypes = {
Expand Down Expand Up @@ -108,11 +121,73 @@ class UsersRouting extends React.Component {
}
}

focusNextPane = () => {
const panesets = document.querySelectorAll('[class^="paneset-"]');
let activePS;
let candidatePane;
panesets.forEach((ps) => {
if (ps.contains(document.activeElement)) {
activePS = ps;
}
});
const panes = activePS.querySelectorAll('[class^="pane-"]');
panes.forEach((p, i) => {
if (p.contains(document.activeElement)) {
if (i === panes.length - 1) {
candidatePane = panes[0];
} else {
candidatePane = panes[i + 1];
}
}
});
const content = candidatePane.querySelector('[class^="paneContent-"]');
let elem = getFirstFocusable(content);
if (!elem) {
elem = candidatePane.querySelector('[class^="paneHeader-"]');
}
elem.focus();
}

focusPrevPane = () => {
const panesets = document.querySelectorAll('[class^="paneset-"]');
let activePS;
let candidatePane;
panesets.forEach((ps) => {
if (ps.contains(document.activeElement)) {
activePS = ps;
}
});
const panes = activePS.querySelectorAll('[class^="pane-"]');
panes.forEach((p, i) => {
if (p.contains(document.activeElement)) {
if (i === 0) {
candidatePane = panes[panes.length - 1];
} else {
candidatePane = panes[i - 1];
}
}
});
const content = candidatePane.querySelector('[class^="paneContent-"]');
let elem = getFirstFocusable(content);
if (!elem) {
elem = candidatePane.querySelector('[class^="paneHeader-"]');
}
elem.focus();
}

shortcuts = [
{
name: 'search',
handler: this.focusSearchField
},
{
name: 'nextPane',
handler: this.focusNextPane
},
{
name: 'previousPane',
handler: this.focusPrevPane
}
];

checkScope = () => {
Expand Down Expand Up @@ -167,7 +242,7 @@ class UsersRouting extends React.Component {
</NavList>
)}
</AppContextMenu>
<CommandList commands={commands}>
<CommandList commands={modifiedCommands}>
<HasCommand
commands={this.shortcuts}
isWithinScope={this.checkScope}
Expand Down Expand Up @@ -228,7 +303,7 @@ class UsersRouting extends React.Component {
<KeyboardShortcutsModal
open
onClose={() => { this.changeKeyboardShortcutsModal(false); }}
allCommands={commands.concat(commandsGeneral)}
allCommands={modifiedCommands.concat(commandsGeneral)}
/>
)}
</ >
Expand Down