Last active
June 28, 2018 06:07
-
-
Save kevinsqi/8bc4d63b5a8599687682b44001c0c1e6 to your computer and use it in GitHub Desktop.
AutoblurSelect - a <select> wrapper that blurs onChange
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
import React from 'react'; | |
class AutoblurSelect extends React.Component { | |
constructor(props) { | |
super(props); | |
this.selectRef = React.createRef(); | |
} | |
onChange = (event) => { | |
this.props.onChange(event); | |
this.selectRef.current.blur(); | |
}; | |
render() { | |
const { children, onChange, ...otherProps } = this.props; | |
return ( | |
<select {...otherProps} onChange={this.onChange} ref={this.selectRef}> | |
{children} | |
</select> | |
); | |
} | |
} | |
export default AutoblurSelect; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment