From c739a8b3cb7c0d8eb5900d66c4079502d5729a0c Mon Sep 17 00:00:00 2001 From: WarisR Date: Tue, 22 Nov 2016 16:27:01 +0700 Subject: [PATCH 1/2] When a user's already changed text then we pass text to this class as props, it should be changed to a text that we passed. (even if it's same as previous text) So isTextChange should compare between this.state.text with this.props.text. --- index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.jsx b/index.jsx index d4e3c90..bc612fc 100644 --- a/index.jsx +++ b/index.jsx @@ -50,7 +50,7 @@ export default class InlineEdit extends React.Component { } componentWillReceiveProps(nextProps) { - const isTextChanged = (nextProps.text !== this.props.text); + const isTextChanged = (this.state.text !== this.props.text); const isEditingChanged = (nextProps.editing !== this.props.editing); let nextState = {}; if (isTextChanged) { From 09a98baaaa74310be709d506a77799ce9ee3671b Mon Sep 17 00:00:00 2001 From: WarisR Date: Tue, 22 Nov 2016 16:40:06 +0700 Subject: [PATCH 2/2] Can pass a function onStartEditing and onFinishEditing as props to be called when a user starts and finishes editing. --- index.jsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.jsx b/index.jsx index bc612fc..d82242f 100644 --- a/index.jsx +++ b/index.jsx @@ -21,7 +21,9 @@ export default class InlineEdit extends React.Component { staticElement: React.PropTypes.string, tabIndex: React.PropTypes.number, isDisabled: React.PropTypes.bool, - editing: React.PropTypes.bool + editing: React.PropTypes.bool, + onStartEditing: React.PropTypes.function, + onFinishEditing: React.PropTypes.function, }; static defaultProps = { @@ -78,6 +80,10 @@ export default class InlineEdit extends React.Component { if (this.props.stopPropagation) { e.stopPropagation() } + + if (this.props.onStartEditing) + this.props.onStartEditing(); + this.setState({editing: true, text: this.props.text}); }; @@ -87,6 +93,9 @@ export default class InlineEdit extends React.Component { } else if (this.props.text === this.state.text || !this.isInputValid(this.state.text)) { this.cancelEditing(); } + + if (this.props.onFinishEditing) + this.props.onFinishEditing(); }; cancelEditing = () => {