嗨如何更改反应选择中箭头图标的颜色 将鼠标悬停在 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'
/>
);
}
这是我在版本中的做法
4.3.1
const style = {
dropdownIndicator: (provided) => ({
...provided,
"svg": {
fill: "red"
}
}),
}
return (
<Select options={renderOptions()} styles={style} />
);
这应该有帮助:
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 删除了不相关的代码以便更好地理解。 :)
当控制组件聚焦时也改变指示器的颜色怎么样?
以下是如何实现这一目标:
dropdownIndicator: (styles, state) => ({
...styles,
color: state.isFocused ? "hsl(0, 0 , 0, 80%)" : "hsl(0, 0 , 0, 60%)",
}),