Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change hover for all elements ( border, text and arrow ) in react-select?

how to change hover for all elements in react-select?

<Select
    name="colors"
    options={colourOptions}
    className="basic-multi-select"
    classNamePrefix="select"
  />

enter image description here

Source host: https://codesandbox.io/s/react-codesandboxer-example-8iq7b

like image 238
recile Avatar asked Aug 01 '19 14:08

recile


1 Answers

To customise your select, you can use the props styles. All the different components you can change are listed here.

To target specifically the hover state you should use the follow pattern:

const styles = {
    control: base => ({
      ...base,
      "&:hover": {
        borderColor: "red"
      }
    })
  };

Other options are available such as the state inside each components depending of what you're trying to achieve.

If you want all the elements to behave depending of the state of the control component you will have to write something like this:

  const styles = {
    control: base => ({
      ...base,
      "&:hover": {
        borderColor: "red",
        color: "red"
      }
    }),
    dropdownIndicator: base => ({
      ...base,
      color: "inherit"
    }),
    singleValue: base => ({
      ...base,
      color: "inherit"
    })
  };

You would probably also kill the animation ease depending of the speed of the effect. You can see a live example here.

like image 139
Laura Avatar answered Sep 20 '22 20:09

Laura