Last active
July 5, 2023 04:32
-
-
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
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"; | |
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