react-hotkeys
react-hotkeys copied to clipboard
[BUG] Autofocus input + simple up/down arrow key works only once
Describe the bug
I have a simple <HotKeys>
with ArrowKeys up/down events declared around with autofocus attribute.
Everything lives in modal.
When modal is rendered and I press up or down arrow then event is emitted only once and works again after re-focus but then only once too.
How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys etc)
const keyMap = {
PREV_ELEM: ['ArrowUp'],
NEXT_ELEM: ['ArrowDown'],
};
const handlers = {
PREV_ELEM: () => {
console.log('up');
},
NEXT_ELEM: () => {
console.log('down', results.length);
}
}
return <Modal open={visible} ...>
<Modal.Content>
<HotKeys keyMap={keyMap} handlers={handlers}>
<Input onChange={e => onType(e.target.value)} autoFocus/>
</HotKeys>
</Modal.Content>
</Modal>;
Expected behavior Modal shows up, input is focused and up/down arrows events are handled.
Platform (please complete the following information):
- Version of react-hotkeys: 2.0.0
- Browser: Chrome
- OS: Win10
Are you willing and able to create a PR request to fix this issue? No
Include the smallest log that includes your issue:
HotKeys (F10๐-C2๐ท-P0๐บ:) Focused.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E199๐): New 'ArrowDown' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:429 HotKeys (GLOBAL-E199๐-C0๐บ): No matching actions found for 'ArrowDown' keydown.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E200๐): New (simulated) 'ArrowDown' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E200๐): Ignored 'ArrowDown' keypress because it doesn't have any keypress handlers.
FocusOnlyKeyEventStrategy.js:298 HotKeys (F10๐-E201๐-C2๐ท-P0๐บ:) New 'ArrowDown' keydown event.
AbstractKeyEventStrategy.js:418 HotKeys (F10๐-E201๐-C0๐บ) Found action that matches 'ArrowDown': NEXT_ELEM. Calling handler . . .
index.js:25 down
FocusOnlyKeyEventStrategy.js:508 HotKeys (F10๐-E201๐-C0๐บ) Stopping further event propagation.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E202๐): New 'ArrowDown' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E202๐): Ignored 'ArrowDown' keyup because it doesn't have any keyup handlers.
FocusOnlyKeyEventStrategy.js:400 HotKeys (F10๐-E202๐-C2๐ท-P0๐บ:) Ignored 'ArrowDown' keyup as it was not expected, and has already been simulated.
EventPropagator.js:252 HotKeys (F10๐-E202๐-Cnull๐บ) Stopping further event propagation.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E203๐งก): New 'ArrowDown' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:429 HotKeys (GLOBAL-E203๐งก-C0๐บ): No matching actions found for 'ArrowDown' keydown.
FocusOnlyKeyEventStrategy.js:298 HotKeys (F10๐-E205๐-C2๐ท-P0๐บ:) New (simulated) 'ArrowDown' keypress event.
GlobalKeyEventStrategy.js:305 HotKeys (GLOBAL-E205๐): Received (simulated) 'ArrowDown' keypress event (that has already passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E205๐): Ignored 'ArrowDown' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E206๐): New 'ArrowDown' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E206๐): Ignored 'ArrowDown' keyup because it doesn't have any keyup handlers.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E207๐): New 'ArrowUp' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:429 HotKeys (GLOBAL-E207๐-C0๐บ): No matching actions found for 'ArrowUp' keydown.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E208๐): New (simulated) 'ArrowUp' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E208๐): Ignored 'ArrowUp' keypress because it doesn't have any keypress handlers.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E209๐งก): New 'ArrowUp' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E209๐งก): Ignored 'ArrowUp' keyup because it doesn't have any keyup handlers.
FocusOnlyKeyEventStrategy.js:220 HotKeys (F10๐-C2๐ท-P0๐บ:) Lost focus.
KeyEventManager.js:167 HotKeys: Window focused - clearing key history
FocusOnlyKeyEventStrategy.js:153 HotKeys (F11๐-C2๐ท-P0๐บ:) Focused.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E210โค๏ธ): New 'ArrowUp' keydown event (that has NOT passed through React app).
AbstractKeyEventStrategy.js:429 HotKeys (GLOBAL-E210โค๏ธ-C0๐บ): No matching actions found for 'ArrowUp' keydown.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E211๐): New (simulated) 'ArrowUp' keypress event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E211๐): Ignored 'ArrowUp' keypress because it doesn't have any keypress handlers.
FocusOnlyKeyEventStrategy.js:298 HotKeys (F11๐-E212๐-C2๐ท-P0๐บ:) New 'ArrowUp' keydown event.
AbstractKeyEventStrategy.js:418 HotKeys (F11๐-E212๐-C0๐บ) Found action that matches 'ArrowUp': PREV_ELEM. Calling handler . . .
index.js:21 up
FocusOnlyKeyEventStrategy.js:508 HotKeys (F11๐-E212๐-C0๐บ) Stopping further event propagation.
GlobalKeyEventStrategy.js:310 HotKeys (GLOBAL-E213๐): New 'ArrowUp' keyup event (that has NOT passed through React app).
GlobalKeyEventStrategy.js:547 HotKeys (GLOBAL-E213๐): Ignored 'ArrowUp' keyup because it doesn't have any keyup handlers.
FocusOnlyKeyEventStrategy.js:400 HotKeys (F11๐-E213๐-C2๐ท-P0๐บ:) Ignored 'ArrowUp' keyup as it was not expected, and has already been simulated.
EventPropagator.js:252 HotKeys (F11๐-E213๐-Cnull๐บ) Stopping further event propagation.
FocusOnlyKeyEventStrategy.js:220 HotKeys (F11๐-C2๐ท-P0๐บ:) Lost focus.
KeyEventManager.js:167 HotKeys: Window focused - clearing key history
What Configuration options are you using?
configure({logLevel: 'debug', ignoreTags: ['select', 'textarea'], ignoreRepeatedEventsWhenKeyHeldDown: false});
I don't know why but it looks that react-hotkeys loosing focus but it is really still present in the Input element
Has there been a PR for this specific issue? i'm having similar issues