From c5195ba8cbc2825b5c1df4ae6e3045d165713b93 Mon Sep 17 00:00:00 2001 From: Lewis Chung Date: Tue, 12 Nov 2019 19:04:04 -0800 Subject: [PATCH] Add contentEditable prop --- src/react-contenteditable.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/react-contenteditable.tsx b/src/react-contenteditable.tsx index 030e4ba..e3ad89f 100644 --- a/src/react-contenteditable.tsx +++ b/src/react-contenteditable.tsx @@ -46,6 +46,14 @@ export default class ContentEditable extends React.Component { render() { const { tagName, html, innerRef, ...props } = this.props; + let contentEditable = this.props.contentEditable === undefined + ? true + : this.props.contentEditable; + + if (this.props.disabled === true) { + contentEditable = false; + } + return React.createElement( tagName || 'div', { @@ -58,7 +66,7 @@ export default class ContentEditable extends React.Component { onBlur: this.props.onBlur || this.emitChange, onKeyUp: this.props.onKeyUp || this.emitChange, onKeyDown: this.props.onKeyDown || this.emitChange, - contentEditable: !this.props.disabled, + contentEditable, dangerouslySetInnerHTML: { __html: html } }, this.props.children); @@ -120,6 +128,14 @@ export default class ContentEditable extends React.Component { } static propTypes = { + contentEditable: PropTypes.oneOf([ + "events", + "caret", + "typing", + "plaintext-only", + true, + false + ]), html: PropTypes.string.isRequired, onChange: PropTypes.func, disabled: PropTypes.bool,