5

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?

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155

2 Answers2

8

Editor component has onEscape property

<Editor 
    editorState={this.state.editorState} 
    onChange={this.onChange.bind(this)} 
    onEscape={keyEvent=>console.log('Escape just  pressed')}
    ref="editor"
/>
acidron
  • 417
  • 4
  • 8
0

We solved this with an onKeyDown handler in the editor's enclosing div. I'm not thrilled with the solution and hope someone has a better one, but this at least works.

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155