Skip to content

Instantly share code, notes, and snippets.

@rakeshpatra
Last active July 5, 2023 04:32
Show Gist options
  • Save rakeshpatra/7badf3fb1629199028b3870ec6865728 to your computer and use it in GitHub Desktop.
Save rakeshpatra/7badf3fb1629199028b3870ec6865728 to your computer and use it in GitHub Desktop.
Configure react-select to hide selected option when clicking on search box or opening menu
import React from "react";
import Select from "react-select";
class CustomSelect extends React.Component {
constructor(props) {
super(props);
this.state = { menuIsOpen: false };
}
render() {
return (
<Select
controlShouldRenderValue={!this.state.menuIsOpen}
onMenuOpen={() => this.setState({ menuIsOpen: true })}
onMenuClose={() => this.setState({ menuIsOpen: false })}
/>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment