11import React , { Component , PropTypes } from 'react'
22import classnames from 'classnames'
33
4- class TodoTextInput extends Component {
5- constructor ( props , context ) {
6- super ( props , context )
7- this . state = {
8- text : this . props . text || ''
9- }
4+ export default class TodoTextInput extends Component {
5+ static propTypes = {
6+ onSave : PropTypes . func . isRequired ,
7+ text : PropTypes . string ,
8+ placeholder : PropTypes . string ,
9+ editing : PropTypes . bool ,
10+ newTodo : PropTypes . bool
11+ }
12+
13+ state = {
14+ text : this . props . text || ''
1015 }
1116
12- handleSubmit ( e ) {
17+ handleSubmit = e => {
1318 const text = e . target . value . trim ( )
1419 if ( e . which === 13 ) {
1520 this . props . onSave ( text )
@@ -19,11 +24,10 @@ class TodoTextInput extends Component {
1924 }
2025 }
2126
22- handleChange ( e ) {
23- this . setState ( { text : e . target . value } )
24- }
27+ handleChange = e => this . setState ( { text : e . target . value } )
2528
26- handleBlur ( e ) {
29+
30+ handleBlur = e => {
2731 if ( ! this . props . newTodo ) {
2832 this . props . onSave ( e . target . value )
2933 }
@@ -40,19 +44,9 @@ class TodoTextInput extends Component {
4044 placeholder = { this . props . placeholder }
4145 autoFocus = "true"
4246 value = { this . state . text }
43- onBlur = { this . handleBlur . bind ( this ) }
44- onChange = { this . handleChange . bind ( this ) }
45- onKeyDown = { this . handleSubmit . bind ( this ) } />
47+ onBlur = { this . handleBlur }
48+ onChange = { this . handleChange }
49+ onKeyDown = { this . handleSubmit } />
4650 )
4751 }
4852}
49-
50- TodoTextInput . propTypes = {
51- onSave : PropTypes . func . isRequired ,
52- text : PropTypes . string ,
53- placeholder : PropTypes . string ,
54- editing : PropTypes . bool ,
55- newTodo : PropTypes . bool
56- }
57-
58- export default TodoTextInput
0 commit comments