Add placeHolder prop for EditableText

pull/1/head
Erik Johnston 2015-07-15 15:04:39 +01:00
parent dfd54f3b95
commit 2b81f46030
2 changed files with 12 additions and 2 deletions

View File

@ -43,14 +43,22 @@ module.exports = React.createClass({
}, },
onFinish: function(ev) { onFinish: function(ev) {
this.setValue(ev.target.value); if (ev.target.value) {
this.setValue(ev.target.value);
} else {
this.cancelEdit();
}
}, },
render: function() { render: function() {
var editable_el; var editable_el;
if (this.state.phase == this.Phases.Display) { if (this.state.phase == this.Phases.Display) {
editable_el = <div ref="display_div" onClick={this.onClickDiv}>{this.state.value}</div>; if (this.state.value) {
editable_el = <div ref="display_div" onClick={this.onClickDiv}>{this.state.value}</div>;
} else {
editable_el = <div ref="display_div" onClick={this.onClickDiv}><i>{this.props.placeHolder}</i></div>;
}
} else if (this.state.phase == this.Phases.Edit) { } else if (this.state.phase == this.Phases.Edit) {
editable_el = ( editable_el = (
<div> <div>

View File

@ -22,6 +22,7 @@ module.exports = {
propTypes: { propTypes: {
onValueChanged: React.PropTypes.func, onValueChanged: React.PropTypes.func,
initalValue: React.PropTypes.string, initalValue: React.PropTypes.string,
placeHolder: React.PropTypes.string,
}, },
Phases: { Phases: {
@ -33,6 +34,7 @@ module.exports = {
return { return {
onValueChanged: function() {}, onValueChanged: function() {},
initalValue: '', initalValue: '',
placeHolder: 'Click to set',
}; };
}, },