3.3.7 • Published 1 year ago

react-contenteditable v3.3.7

Weekly downloads
57,890
License
Apache-2.0
Repository
github
Last release
1 year ago

react-contenteditable

React component for a div with editable contents

Build Status download count bundle size license

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

propdescriptiontype
innerRefelement's ref attributeObject | Function
htmlrequired: innerHTML of the editable elementString
disableduse true to disable editingBoolean
onChangecalled whenever innerHTML changesFunction
onBlurcalled whenever the html element is blurredFunction
onFocusevent fires when an element has received focusFunction
onKeyUpcalled whenever a key is releasedFunction
onKeyDowncalled whenever a key is pressedFunction
classNamethe element's CSS classString
stylea collection of CSS properties to apply to the elementObject

Known Issues

If you are using hooks, please see this issue. Using this component with useState doesn't work, but you can still use useRef :

const text = useRef('');

const handleChange = evt => {
    text.current = evt.target.value;
};

const handleBlur = () => {
    console.log(text.current);
};

return <ContentEditable html={text.current} onBlur={handleBlur} onChange={handleChange} />

Examples

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

@hhgtech/hhg-components@jessjess/react-site-componentsec-components-reactminsilo-react-client@dewen_li/componentsform-builder-migrationstuff-ui2@monroeclinton/diction@custiv/design-system@monroeclinton/editor@waroio/waro-package@pxwlab/katana-cb@elijahjpassmore/qwc2great-editorreact-screen-shot-simple@infinitebrahmanuniverse/nolb-react-con@noahbaron91/layers@everything-registry/sub-chunk-2547@criya/app-theme@criya/app-theme-v2centricminds-uicir-mentionsbxx-slate-editor@dashup/ui@crystaldesign/diva-chat-react@dewcms/block-editor@dewcms/section-ui@decooda/generic-questions@decooda/rating-questionsconstructicon@deeptrekker/reactcontent-editable-component@craftjs/layers@craftjs-noahb/layerscryoiq-componentscryoiq-frameworkcraft-codeless-designernb-base@engraft/shared@evlop/coremy-app-haulcmfe-user-templatemohimmatech-ui@ef2/strapi-plugin-bold-title-editorlowcode-demo-stdokui-menulwj-business-frontendlwj-editorlive-bridge-widgetdeseruntnamlibrary-ts2delta-componentmystic-soundmytest-abc@fikasio/react-ui-components@jefrydco/craftjs-layers@infotech/uikit-datagrid@izikaj/minimal-editorpagenoteobject-editor@incresco/design-system-reactopen-source-lawmc-tf-testm-dash-ui@gedit/render-engine-phaser-ide@hexx/editornitratenovitas-auth-reactns1-guins-draganddroppewo.componentssimple-rich-text-editor-in-reactnmtsmartformsdksabziskills-application-video@salesforce/design-system-reactenchantosnotechoudvlsc-test-001epanel@thebitbybit/craftjs-layersstuff-ui@together.biz/katana-cb@terralego/corezip-link-ui-componentsformula-editorronds-metadatasdc-react-editors@railsware/outline-checklistsdk-chat-widgetsdk-chat-widget-testeditable-react-tableeditheiusmaximeslash-rich-text-editor@selfdecode/sd-component-library@suncel/nextjs@tadamus/wpuiwp-servicessurveyfunnel2
3.3.7

1 year ago

3.3.6

3 years ago

3.3.5

4 years ago

3.3.4

4 years ago

3.3.3

4 years ago

3.3.2

5 years ago

3.3.1

5 years ago

3.3.0

5 years ago

3.2.6

5 years ago

3.2.5

5 years ago

3.2.4

5 years ago

3.2.3

5 years ago

3.2.2

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.0

6 years ago

2.1.6

6 years ago

2.1.5

6 years ago

2.1.4

6 years ago

2.1.3

6 years ago

2.1.2

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

7 years ago

2.0.4

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

8 years ago

1.1.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.0.2-1

8 years ago

0.0.3

8 years ago

0.0.2

9 years ago

0.0.1

9 years ago

0.0.0

9 years ago