-
Notifications
You must be signed in to change notification settings - Fork 42
WIP: pane switching keyboard shortcuts - #1709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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'; | ||
|
|
||
| import { AppContextMenu, Route, Switch, IfPermission } from '@folio/stripes/core'; | ||
| import { | ||
|
|
@@ -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' | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, no
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }, | ||
| { | ||
| name: 'previousPane', | ||
| shortcut: 'shift + pageup' | ||
| }, | ||
| ]; | ||
|
|
||
| class UsersRouting extends React.Component { | ||
| static propTypes = { | ||
|
|
@@ -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 = () => { | ||
|
|
@@ -167,7 +242,7 @@ class UsersRouting extends React.Component { | |
| </NavList> | ||
| )} | ||
| </AppContextMenu> | ||
| <CommandList commands={commands}> | ||
| <CommandList commands={modifiedCommands}> | ||
| <HasCommand | ||
| commands={this.shortcuts} | ||
| isWithinScope={this.checkScope} | ||
|
|
@@ -228,7 +303,7 @@ class UsersRouting extends React.Component { | |
| <KeyboardShortcutsModal | ||
| open | ||
| onClose={() => { this.changeKeyboardShortcutsModal(false); }} | ||
| allCommands={commands.concat(commandsGeneral)} | ||
| allCommands={modifiedCommands.concat(commandsGeneral)} | ||
| /> | ||
| )} | ||
| </ > | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can import
getFirstFocusabledirectly from@folio/stripes/components; you don't have to reach in and get it by private path.