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

问题描述 投票:0回答:4

嗨如何更改反应选择中箭头图标的颜色 将鼠标悬停在 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'
    />
  );
}
reactjs react-select
4个回答
18
投票

只需使用

customStyles
并为
dropdownIndicator
元素声明一个新颜色:

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

在这里您可以找到所有元素的列表以及这里一个实例。


5
投票

这是我在版本中的做法

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'
    />
  );
}

PS 删除了不相关的代码以便更好地理解。 :)


0
投票

当控制组件聚焦时也改变指示器的颜色怎么样?

以下是如何实现这一目标:

dropdownIndicator: (styles, state) => ({
  ...styles,
  color: state.isFocused ? "hsl(0, 0 , 0, 80%)" : "hsl(0, 0 , 0, 60%)",
}),
© www.soinside.com 2019 - 2024. All rights reserved.