| 2 | import handleChange from 'MIXIN/handleChange' |
| 3 | |
| 4 | export default class TodoInput extends Component { |
| 5 | constructor (props) { |
| 6 | super(props) |
| 7 | this.state = { inputVal: '' } |
| 8 | this.handleChange = handleChange.bind(this) |
| 9 | } |
| 10 | |
| 11 | handleSubmit () { |
| 12 | let content = this.state.inputVal.trim() |
| 13 | if (!content) return |
| 14 | |
| 15 | this.props.addTodo(content) |
| 16 | this.setState({ inputVal: '' }) // 清空输入框 |
| 17 | } |
| 18 | |
| 19 | render () { |
| 20 | return ( |
| 21 | <form onSubmit={ |
| 22 | (e) => { |
| 23 | e.preventDefault() // 防页面跳转 |
| 24 | this.handleSubmit() |
| 25 | } |
| 26 | }> |
| 27 | <div className="form-group"> |
| 28 | <input |
| 29 | type="text" |
| 30 | className="form-control" |
| 31 | name="inputVal" |
| 32 | placeholder="请输入待办事项,敲回车确认添加" |
| 33 | required |
| 34 | value={this.state.inputVal} |
| 35 | onChange={this.handleChange} /> |
| 36 | </div> |
| 37 | |
| 38 | </form> |
| 39 | ) |
| 40 | } |
| 41 | } |
nothing calls this directly
no outgoing calls
no test coverage detected