Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change color arrow icon react-select

hi how to change color of arrow icon in react-select in mouse over in google chrome, I find CSS variable but I cant change color. this value of CSS css-tlfecz-indicatorContainer. in my customStyles I wrote this line but not working:

  indicatorContainer:base =>({
        ...base,
       color:'#000000'
     }),

enter image description here

UPDATE

this is my component I use react-select

import React from 'react';
import Select from 'react-select';
export default function DropDown(props) {
  const customStyles = {
    control: (base, state) => ({
      ...base,
      background: "#59c5b8",
      borderRadius: 0,

    }),
    menu: base => ({
      ...base,
      // override border radius to match the box
      borderRadius: 20,
      // kill the gap
      marginTop: 0,

    }),
    menuList: base => ({
      ...base,
      // kill the white space on first and last option
      padding: 0
    }),
    indicatorSeparator: base => ({
      ...base,
      display: 'none'
    }),
    myDropDown__indicator: base => ({
      ...base,
      '&.myDropDown__dropdown-indicator': {
        '&.indicatorContainer': {
          color: '#000000'
        }
      }

    }),
    '&.indicatorContainer': {
      color: '#000000'
    }
  };


  const [selectedOption, setSelectedOption] = React.useState(0);

  const handleChange = selectedOption => {

    setSelectedOption(selectedOption)

    props.parentCallBack(selectedOption)
  };
  return (
    <Select


      isSearchable={false}
      styles={customStyles}
      isOptionDisabled={true}
      defaultValue={props.options[0]}
      isRtl={true}
      onChange={handleChange}
      options={props.options}
      classNamePrefix='myDropDown'
    />
  );
}
like image 255
Amir Farahani Avatar asked Jan 04 '20 13:01

Amir Farahani


People also ask

How do I change the color of my arrow in react-select?

Just use customStyles and declare a new colour for dropdownIndicator element: const customStyles = { dropdownIndicator: base => ({ ... base, color: "red" // Custom colour }) }; Here you can find the list of all the elements and here a live example.

How do I change the arrow color in select material UI?

To change the color of Select component's border and arrow icon with React Material UI, we can use the '&:before' and '&:after' selectors and apply the styles for them. We call makeStyles with a function that returns an object with the select property set to an object with the drop down styles.

How do you change color of placeholder in react-select?

You can update the placeholder styles using the same colourStyles object. You can review the related documentation (https://react-select.com/styles#style-object) to check the keys available for styling.


3 Answers

Just use customStyles and declare a new colour for dropdownIndicator element:

const customStyles = {
  dropdownIndicator: base => ({
    ...base,
    color: "red" // Custom colour
  })
};

Here you can find the list of all the elements and here a live example.

like image 102
Laura Avatar answered Oct 10 '22 20:10

Laura


Here is how I did it in version 4.3.1

const style = {
  dropdownIndicator: (provided) => ({
    ...provided,
    "svg": {
      fill: "red"
    }
  }),
}

return (
  <Select options={renderOptions()} styles={style} />
);

like image 42
Michal Kurowski Avatar answered Oct 10 '22 20:10

Michal Kurowski


This should help:

import React from 'react';
import Select from 'react-select';

export default function DropDown(props) {
  const customStyles = {
    indicatorsContainer: () => ({
      '.myDropDown': {
        '&__dropdown-indicator': {
          color: 'red' // <--- Color of your choice
        }
      }
    })
  };

  return (
    <Select
      styles={customStyles}
      classNamePrefix='myDropDown'
    />
  );
}

PS Removed non-related code for better understanding. :)

like image 2
UtkarshPramodGupta Avatar answered Oct 10 '22 20:10

UtkarshPramodGupta