更改 React-Select 中的颜色箭头图标

10

你好,如何在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'
    />
  );
}

你正在使用哪个版本的 react-select? - UtkarshPramodGupta
@UtkarshPramodGupta v3.0.8 - Amir Farahani
请展示您实现React-Select的代码。 - UtkarshPramodGupta
@UtkarshPramodGupta,感谢你帮忙更新我的问题。 - Amir Farahani
3个回答

17

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

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

这里可以找到所有元素列表,这里有一个实时示例。


4

这是我在版本 4.3.1 中的做法:

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

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


2
这应该会有所帮助:
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'
    />
  );
}

为更好的理解,已删除与此无关的代码。 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接