Skip to content

Instantly share code, notes, and snippets.

@giautm
Last active March 27, 2016 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giautm/c0f14e1adfb3ed67f02f to your computer and use it in GitHub Desktop.
Save giautm/c0f14e1adfb3ed67f02f to your computer and use it in GitHub Desktop.
BarcodeInput component
var BarcodeInput = React.createClass({
propTypes: {
onInput: React.PropTypes.func.isRequired,
placeholder: React.PropTypes.string
},
handleKeyUp: function(event) {
if (event.keyCode === 13 || event.which === 13) {
this.props.onInput(event.target.value);
event.target.select();
}
},
handleOnClick: function (event) {
event.target.select();
},
getDefaultProps: function() {
return {
placeholder: 'Input barcode'
};
},
render: function() {
return (
<input type="text" placeholder={this.props.placeholder}
onKeyUp={this.handleKeyUp} onClick={this.handleOnClick}/>
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment