npm

Don't miss out on this year's npm Pride t-shirt designs!Order your favorites here »

react-contenteditable

3.2.6 • Public • Published

react-contenteditable

React component for a div with editable contents

Build Status

Install

npm install react-contenteditable

Usage

import React from 'react'
import ContentEditable from 'react-contenteditable'
 
class MyComponent extends React.Component {
  constructor() {
    super()
    this.contentEditable = React.createRef();
    this.state = {html: "<b>Hello <i>World</i></b>"};
  };
 
  handleChange = evt => {
    this.setState({html: evt.target.value});
  };
 
  render = () => {
    return <ContentEditable
              innerRef={this.contentEditable}
              html={this.state.html} // innerHTML of the editable div
              disabled={false}       // use true to disable editing
              onChange={this.handleChange} // handle innerHTML change
              tagName='article' // Use a custom HTML tag (uses a div by default)
            />
  };
};

Available props

prop description type
innerRef element's ref attribute Object | Function
html required: innerHTML of the editable element String
disabled use true to disable editing Boolean
onChange called whenever innerHTML changes Function
onBlur called whenever the html element is blurred Function
onKeyDown called whenever the backspace press Function
className the element's CSS class String
style a collection of CSS properties to apply to the element Object

Examples

You can try react-contenteditable right from your browser to see if it fits your project's needs:

install

npm i react-contenteditable

Downloadsweekly downloads

16,731

version

3.2.6

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability