lovasoa / react-contenteditable

React component for a div with editable contents
http://npmjs.com/package/react-contenteditable
Apache License 2.0
1.64k stars 218 forks source link

Start editing the element through code? #222

Closed crysfel closed 3 years ago

crysfel commented 3 years ago

Hi folks! This is an awesome project, thanks for sharing it!

I'd like to know if it's possible to start editing the element through code? For example, I want to add an edit button, when clicking it I want to make the text editable and set the cursor at the end of the text.

Would something like that be possible?

Thanks!

crysfel commented 3 years ago

I was able to it by just giving the focus to the editable element:

onDoubleClick = () => {
    this.setState({ disabled: false });
    setTimeout(() => {
      this.node.current.focus();
    }, 0);
  }