Created
April 20, 2017 17:39
-
-
Save mathdroid/454cb71f95f103307af20031976fca14 to your computer and use it in GitHub Desktop.
Select
This file contains hidden or 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
import { Component } from "react"; | |
export default class Selector extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
value: "a", | |
num: 0 | |
}; | |
this.handleChange = this.handleChange.bind(this); | |
this.handleChangeNum = this.handleChangeNum.bind(this); | |
} | |
handleChange({ target: { value } }) { | |
const { num } = this.state; | |
const shouldResetValue = value === "d"; | |
this.setState({ value, num: shouldResetValue ? 0 : num }); | |
} | |
handleChangeNum({ target: { value } }) { | |
this.setState({ num: value }); | |
} | |
render() { | |
const { value, num } = this.state; | |
return ( | |
<div> | |
<h1>Hiya value = {value} num = {num}</h1> | |
<select value={value} onChange={this.handleChange}> | |
<option value={"a"}>A</option> | |
<option value={"b"} disabled={value === "a"}>B</option> | |
<option value={"c"}>C</option> | |
<option value={"d"}>Reset number selections</option> | |
</select> | |
<select value={num} onChange={this.handleChangeNum}> | |
<option value={0} disabled>Select num</option> | |
<option value={1}>1</option> | |
<option value={2}>2</option> | |
<option value={3}>3</option> | |
<option value={4}>4</option> | |
</select> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment