Last active
September 3, 2015 18:35
-
-
Save rileybracken/810c616cc24a46ab3de8 to your computer and use it in GitHub Desktop.
MaterialSelect
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
var MaterialSelect = React.createClass({ | |
getInitialState: function() { | |
return { | |
open: false, | |
inputValue: this.props.placeholder, | |
options: this.props.options | |
} | |
}, | |
_triggerOpen: function() { | |
this.setState({ open: true }); | |
}, | |
_triggerClose: function(index) { | |
this.setState({ | |
open: false, | |
inputValue: this.state.options[index] | |
}); | |
}, | |
render: function() { | |
var dropdownClass = this.state.open ? 'material-dropdown-menu open' : 'material-dropdown-menu'; | |
var roomList = this.state.options.map(function(room, i) { | |
return <li key={i} onClick={this._triggerClose.bind(this, i)}>{room}</li> | |
}.bind(this)); | |
return ( | |
<div className="material-button-group" > | |
<span onClick={this._triggerOpen} className="material-input">{this.state.inputValue}</span> | |
<ul className={dropdownClass} > | |
{ roomList } | |
</ul> | |
<input type="hidden" value={this.state.inputValue} /> | |
</div> | |
); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment