Skip to content

Unable to change react-select selected value color when menu is clicked #5174

Answered by sheikhumar93
sheikhumar93 asked this question in Q&A
Discussion options

You must be logged in to vote

@adeeb1 I created this small function and called it with styles={customStyles()} in my Select component. I checked with React Dev Tools and only the control component has the property menuIsOpen which tracks whenever a user clicks/taps on the search bar.

const customStyles = () => {
  let menuOpen = false;
  return {
    control: (styles, state) => {
      menuOpen = state.menuIsOpen;
      return { ...styles };
    },
    singleValue: (styles, _) => {
      let color = "black";
      if (menuOpen) {
        color = "gray";
      } else {
        color = "black";
      }
      return {
        ...styles,
        color: color,
      };
    },
  };
};

I just set the color to gray but of co…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by sheikhumar93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants