Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get draft.js to recognize the escape key?

I would like to cancel input and clear the field in my app when the user types the escape key. We tried testing for e.which === 27 in the keyBindingFn, but that function is never even invoked when the escape key is pressed (it is invoked just fine for normal keys, modifier keys, and arrow keys). How can I detect an Escape keypress in draft.js?

like image 215
Carl Manaster Avatar asked Jul 15 '16 17:07

Carl Manaster


People also ask

How to detect escape key press with JavaScript?

To detect escape key press, keyup or keydown event handler will be used in jquery. It will trigger over the document when the escape key will be pressed from the keyboard. keyup event: This event is fired when key is released from the keyboard. keydown event: This event is fired when key is pressed from the keyboard.

How do I turn off modal on Escape key?

Modal Options This modal can be closed with the escape key on your keyboard. Note: You need to press the tab key on the keyboard to first enter the modal window, and then press the Esc key.

What is escape keycode?

On computer keyboards, the Esc key Esc (named Escape key in the international standard series ISO/IEC 9995) is a key used to generate the escape character (which can be represented as ASCII code 27 in decimal, Unicode U+001B, or Ctrl + [ ).


1 Answers

Editor component has onEscape property

<Editor 
    editorState={this.state.editorState} 
    onChange={this.onChange.bind(this)} 
    onEscape={keyEvent=>console.log('Escape just  pressed')}
    ref="editor"
/>
like image 146
acidron Avatar answered Sep 30 '22 20:09

acidron