更改颜色箭头图标反应选择

时间:2020-01-04 13:42:47

标签: reactjs react-select

hi如何在react-select中更改箭头图标的颜色 在谷歌浏览器的鼠标悬停,我发现CSS变量,但我不能更改颜色。 CSS css-tlfecz-indicatorContainer的此值。 在我的customStyles中,我写了这一行,但是没有用:

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

enter image description here

更新

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

3 个答案:

答案 0 :(得分: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'
    />
  );
}

PS删除了无关的代码,以更好地理解。 :)

答案 1 :(得分:2)

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

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

Here,您可以找到所有元素的列表,并here个在线示例。

答案 2 :(得分:1)

这是我在版本 4.3.1

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

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

相关问题