更改颜色箭头图标反应-select

change color arrow icon react-select

嗨,如何在 React 中更改箭头图标的颜色-select 将鼠标悬停在 google chrome 上,我发现 CSS 变量但无法更改颜色。 CSS css-tlfecz-indicatorContainer 的这个值。 在我的 customStyles 中,我写了这一行但没有用:

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

更新

这是我使用的组件 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'
    />
  );
}

这应该有帮助:

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 删除了不相关的代码以便更好地理解。 :)

只需使用 customStyles 并为 dropdownIndicator 元素声明新颜色:

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

Here you can find the list of all the elements and here一个活生生的例子。

这是我在 4.3.1

版本中的做法
const style = {
  dropdownIndicator: (provided) => ({
    ...provided,
    "svg": {
      fill: "red"
    }
  }),
}

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