React-draft-wysiwyg: How to change the behavior when I press enter key

Created on 25 May 2017  路  4Comments  路  Source: jpuri/react-draft-wysiwyg

Hi!

In this component, it makes new paragraph(<p>tag) to press enter key.
On the other hand, when I press shit + enter, it makes just new line(<br />tag).

I want to replace these key bind. Is it possible?
Do you have any idea?

Thanks!

Most helpful comment

Hi @gyarasu ,

You can pass handleReturn as property to editor. Almost all the props of DraftJS are supported by the editor. https://draftjs.org/docs/api-reference-editor.html#handlereturn

All 4 comments

Hi @gyarasu ,

You can pass handleReturn as property to editor. Almost all the props of DraftJS are supported by the editor. https://draftjs.org/docs/api-reference-editor.html#handlereturn

Thanks, @jpuri .
I got it:)

@gyarasu do you have an example of successfully overwriting the handleReturn method by any chance?

@paulhan221
you can pass your own function to handleReturn.

handleReturn={this.myHandleReturn}

class MyEditor extends Component {
  constructor(props) {
    super(props);
    this.myHandleReturn = this.myHandleReturn.bind(this);
  }

  myHandleReturn(e) {
    console.log('hogehoge')
  }

  render() {
    return (
      <div>
        <div>
          <Editor
           ...
            handleReturn={this.myHandleReturn}
            ...
          />
        </div>
      </div>
    );
  }
}
Was this page helpful?
0 / 5 - 0 ratings