Skip to content

Commit

Permalink
added rich text key commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian Krispel-Samsel committed Jun 16, 2017
1 parent 7c7e299 commit 16d29d7
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/App.js
@@ -1,5 +1,5 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Editor, EditorState } from 'draft-js'; import { Editor, EditorState, RichUtils } from 'draft-js';


class App extends Component { class App extends Component {
constructor() { constructor() {
Expand All @@ -13,10 +13,22 @@ class App extends Component {
this.setState({ editorState }); this.setState({ editorState });
}; };


handleKeyCommand = (command) => {
const newState = RichUtils.handleKeyCommand(this.state.editorState, command);

if (newState) {
this.onChange(newState);
return 'handled';
}

return 'not-handled';
}

render() { render() {
return ( return (
<Editor <Editor
editorState={this.state.editorState} editorState={this.state.editorState}
handleKeyCommand={this.handleKeyCommand}
onChange={this.onChange} onChange={this.onChange}
/> />
); );
Expand Down

0 comments on commit 16d29d7

Please sign in to comment.