Last active
October 23, 2016 12:56
-
-
Save tldeti/686be367842f0d562f5b559a277d1099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import './shared.css' | |
import InplaceEditable from './InplaceEditable' | |
export class InplaceEditableText extends Component{ | |
/** | |
* @override | |
* @type {string} | |
*/ | |
render() { | |
<InplaceEditable {...this.props} renderNormal={this.renderNormal} renderEditing={this.renderEditing}> | |
} | |
componentClassnamePrefix = 'inplace-editable-text' | |
renderNormal (editable) { | |
return <span>{this.props.value}</span> | |
} | |
renderEditing (editable) { | |
return <input className="ant-input" | |
value={editable.state.localValue} | |
onChange={e => editable.setState({localValue: e.target.value})} | |
onKeyDown={e=>this.onKeyDown(e,editable)} | |
autoFocus/> | |
} | |
onKeyDown = (e,editable) => { | |
switch (e.keyCode) { | |
case 27: // Escape | |
editable.onCancel() | |
break | |
case 13: // Enter | |
editable.onOK() | |
break | |
default: | |
break | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment