Reader | Centralize Keyboard Shortcuts #3977
Labels
Priority: Low
Reported issue, not a blocker. "Last in" priority for new work.
Product: caseflow-reader
Team: Whiskey
Type: Enhancement
Enhancement to an existing feature
Reader is at a point where we should begin centralizing keyboard shortcuts, such that we can redirect built-in key behavior, trigger different behavior based on what element has focus, etc. (see #3824)
The solution should address two issues: Dispatching an action based on what element has focus, and stacking callbacks. Focus may be defined as
document.activeElement
, or simply as the component that bound a callback last (i.e. a modal).Some relevant implementations include:
<ShortcutProvider/>
wrapper with its own state that updates its children when a key combo has been pressed, and when it's been handledReact.createClass()
keyboardjs
.The decorator and shortcutJS seem like our best options at this point: the
<ShortcutProvider/>
seems like it would get complicated quickly with multiple callbacks per key combo (and can only trigger behavior on children it wraps),react-hotkeys
doesn't support ES6 classes (which don't support mixins), and Mousetrap only supports one callback per combo (uses Objects instead of Sets).The main issue I found with the decorator /
keyboardjs
approach is that it's unclear how the events are bound—oftentimes we want a handler to respond even if its creator isn't the active element, but shortcuts didn't fire reliably even whenkeyboardJS.watch()
was run, which is supposed to bind shortcuts towindow
.After the maintainer of KeyboardJS rejected a PR to modernize the project and update it to ES6, the author of that PR created ShortcutJS. ShortcutJS seems promising, though it does have a few issues: debugging is difficult, the docs are sparse, and it doesn't support Escape at the moment (used to hide the search bar).
PRs pending on ShortcutJS:
fix(EventProcessor): Clean combo after triggering shortcut with Cmd
feat(KeyContainer): Add Escape support to KeyContainer
feat(KeyContainer): Add Tab support
feat(EventProcessor): Add option to reverse Action processing
feat(Shortcut): Add removeAction function
The text was updated successfully, but these errors were encountered: