The library for web and native user interfaces.
Add TODOMVC features
petehunt committed
Jun 3, 2013 at 00:34 UTC
83b8ad7a312b425f75ba2cc2a5773d6dc2a053f8
1 file changed
+12
-1
examples/todomvc/js/app.js
+12
-1
@@ -44,6 +44,11 @@ var TodoItem = React.createClass({
44
this.props.onEdit();
45
this.refs.editField.getDOMNode().focus();
46
}),
47
+ handleKey: React.autoBind(function(event) {
48
+ if (event.nativeEvent.keyCode === 27) {
49
+ this.handleSubmit();
50
+ }
51
+ }),
52
render: function() {
53
return (
54
<li class={cx({completed: this.props.todo.completed, editing: this.props.editing})}>
@@ -58,7 +63,13 @@ var TodoItem = React.createClass({
63
<button class="destroy" onClick={this.props.onDestroy} />
64
</div>
65
<form onSubmit={this.handleSubmit}>
61
- <input ref="editField" class="edit" value={this.props.todo.title} />
66
+ <input
67
+ ref="editField"
68
+ class="edit"
69
+ value={this.props.todo.title}
70
+ onBlur={this.handleSubmit}
71
+ onKeyDown={this.handleKey}
72
+ />
73
<input type="submit" class="submitButton" />
74
</form>
75
</li>