Created
June 3, 2018 04:26
-
-
Save qswitcher/dd5aa8bad50c424be5a4bec010221482 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
const priorities = ['High', 'Med', 'Low']; | |
class TodoForm extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { priority: priorities[2] }; | |
} | |
onSelect = event => { | |
this.setState({ priority: event.value }); | |
}; | |
render() { | |
const addTodo = this.props.addTodo; | |
let input; | |
let select; | |
return ( | |
<div className="TodoForm"> | |
<input | |
type="text" | |
data-testid="TodoForm-input" | |
className="TodoForm-input" | |
placeholder="Enter todo text" | |
ref={node => { | |
input = node; | |
}} | |
/> | |
<select | |
data-testid="PrioritySelect" | |
value={this.state.priority} | |
onChange={this.onSelect} | |
name="taskPriority" | |
ref={node => { | |
select = node; | |
}} | |
> | |
{priorities.map(priority => ( | |
<option key={priority} value={priority}> | |
{priority} | |
</option> | |
))} | |
</select> | |
<button | |
className="TodoForm-button" | |
onClick={() => { | |
addTodo({ text: input.value, priority: this.state.priority }); | |
input.value = ''; | |
}} | |
> | |
Add | |
</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment