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?
How can I get draft.js to recognize the escape key?
Asked Answered
Editor component has onEscape property
<Editor
editorState={this.state.editorState}
onChange={this.onChange.bind(this)}
onEscape={keyEvent=>console.log('Escape just pressed')}
ref="editor"
/>
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.
© 2022 - 2024 — McMap. All rights reserved.