Skip to content

Instantly share code, notes, and snippets.

@WillSams
Created April 26, 2018 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillSams/5479cd5edcc75c8b52e13acbd275f824 to your computer and use it in GitHub Desktop.
Save WillSams/5479cd5edcc75c8b52e13acbd275f824 to your computer and use it in GitHub Desktop.
React-Wysiwyg via extend React.Component
var React = require('react')
var ReactDOM = require('react-dom')
var ContentEditable = require('react-wysiwyg')
class Example extends React.Component {
constructor(props){
super(props)
this.state = {
text: '',
editing: false
}
}
render(){
return (
<div>
<ContentEditable
tagName='div'
className='BlogCommentBox'
onChange={this.onChange}
text={this.state.text}
placeholder='Your Name'
autofocus={true}
maxLength={200}
editing={this.state.editing}
/>
<button onClick={this.enableEditing}>
Enable Editing
</button>
</div>
)
}
onChange(text) {
// in order to render the updated text,
// you need to pass it as a prop to contentEditable.
// This gives you increased flexibility.
this.setState({ text: text });
}
enableEditing(){
// set your contenteditable field into editing mode.
this.setState({ editing: true });
}
}
document.addEventListener('DOMContentLoaded', function() {
var elm = document.getElementById('myDiv')
if (elm) { ReactDOM.render(<Example />, elm) }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment