Skip to content

Commit

Permalink
Handle commit of mixed values unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Apr 1, 2017
1 parent 347f8d1 commit 1a27ac9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/components/editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ class Editable extends PureComponent {
}
}

stop = () => {
stop = (isCommit) => {
const { onCancel, onChange } = this.props

if (this.changed) {
onChange(this.state.value)
} else {
onCancel()
onCancel(isCommit)
}
}

Expand All @@ -57,7 +57,7 @@ class Editable extends PureComponent {
this.cancel()
break
case 'Enter':
this.stop()
this.stop(true)
break
}

Expand Down
12 changes: 10 additions & 2 deletions src/components/metadata/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,17 @@ class MetadataField extends PureComponent {
})
}

handleCancel = (isCommitUnchanged) => {
if (isCommitUnchanged) {
return this.handleChange(this.props.text)
}

this.props.onEditCancel()
}

render() {
const { classes, details, label } = this
const { text, isEditing, isDisabled, onEditCancel } = this.props
const { text, isEditing, isDisabled } = this.props

return (
<li className={cx(classes)}>
Expand All @@ -65,7 +73,7 @@ class MetadataField extends PureComponent {
value={text}
isDisabled={isDisabled}
isEditing={isEditing}
onCancel={onEditCancel}
onCancel={this.handleCancel}
onChange={this.handleChange}/>
</div>
</li>
Expand Down

0 comments on commit 1a27ac9

Please sign in to comment.