Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isTextChange should compare between this.state.text with this.props.text #29

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -50,7 +52,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) {
Expand Down Expand Up @@ -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});
};

Expand All @@ -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 = () => {
Expand Down