React Prevent Select Close
by Alan Thomas
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://npmcdn.com/react@latest/dist/react-with-addons.js"></script>
<script src="https://npmcdn.com/react-dom@latest/dist/react-dom.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration-babel.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
JavaScript 1.7
class Container extends React.Component {
constructor(props) {
super(props);
this.state = {
selectValue: ''
};
}
handleSelectChange(event) {
this.setState({
selectValue: event.target.value
});
event.stopPropagation();
//event.preventDefault();
}
render() {
return (
<div>
<p>Select Input</p>
<select onChange = {this.handleSelectChange.bind(this)}
value = {this.state.selectValue}>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
);
}
}
ReactDOM.render( < Container / > ,
document.getElementById('container')
);