Skip to content

Instantly share code, notes, and snippets.

@kevinsqi
Last active June 28, 2018 06:07
Show Gist options
  • Save kevinsqi/8bc4d63b5a8599687682b44001c0c1e6 to your computer and use it in GitHub Desktop.
Save kevinsqi/8bc4d63b5a8599687682b44001c0c1e6 to your computer and use it in GitHub Desktop.
AutoblurSelect - a <select> wrapper that blurs onChange
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