hi如何在react-select中更改箭头图标的颜色
在谷歌浏览器的鼠标悬停,我发现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'
/>
);
}
答案 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
})
};
答案 2 :(得分:1)
这是我在版本 4.3.1
const style = {
dropdownIndicator: (provided) => ({
...provided,
"svg": {
fill: "red"
}
}),
}
return (
<Select options={renderOptions()} styles={style} />
);