greena13 / react-hotkeys

Declarative hotkey and focus area management for React
https://github.com/greena13/react-hotkeys
ISC License
2.15k stars 160 forks source link

[BUG] Text input gets populated with the ketMap sequence keys #267

Open MarioKrstevski opened 4 years ago

MarioKrstevski commented 4 years ago

Describe the bug I have an action happening on space+b but never the less, any other combination acts the same. In my case, I need to select and focus a text input and make it available to start typing, but the letter 'b' gets typed into the input.

Not really sure if it is a bug, but I tried to search for a fix/right approach, but couldn't find one. IF a solution exist please point it out.

How are you using react hotkeys components? (HotKeys, GlobalHotKeys, IgnoreKeys, etc)

   const keyMap = {
        FOCUS_BARCODE_INPUT: 'b+space',
    }

    const keyMapHandlers = {
        FOCUS_BARCODE_INPUT: () => {
            document.getElementById('barcode-input-field').focus()
            // Code for Toast message to appear, indicating we are in typing mode and they can type/scan barcodes 
    }
  <HotKeys
                keyMap={keyMap}
                handlers={keyMapHandlers}
            >
 <App> ... </App>
</Hotkeys>

Expected behavior I don't want this behavior. I just want the trigger sequence to not be used as my new input

Platform (please complete the following information):

Are you willing and able to create a PR request to fix this issue? No Include the smallest log that includes your issue:

Set logging to verbose (you'll need the development build if its possible):

import { configure } from 'react-hotkeys';

configure({
  logLevel: 'verbose'
})

What Configuration options are you using?

configure({
  //options
})
MasterLambaster commented 4 years ago

@MarioKrstevski you need to cancel event in order to prevent input, i.e

const keyMapHandlers = {
  FOCUS_BARCODE_INPUT: (event) => {
    event.preventDefault();
    document.getElementById('barcode-input-field').focus()
  }
}

This is not a bug, that's intended behavior.