dig*_*ill 3 reactjs react-select
我想使用 react-select 并在将页面背景颜色从白色更改为自定义后遇到了一系列问题。(问题在白色背景上并不像在 react-select 的 github 页面上那么明显)
我正在通过样式道具执行上述操作,因为 className 道具无法正常工作。
这是样式道具。
const colourStyles = {
control: styles => ({ ...styles, backgroundColor: '#023950', color: 'white', border: 0 }),
option: (styles) => {
return {
backgroundColor: '#023950',
color: 'white'
};
},
singleValue: styles => ({ ...styles, color: 'white' }),
};
Run Code Online (Sandbox Code Playgroud)
这是问题列表,如果有人可以帮助解决这些问题。请参考附图。
在下面的示例中,您将找到不同观点的答案。
您提到的前 4 点可以通过编辑 style-in-JS 来解决,如下所示:
const customStyles = {
control: (base, state) => ({
...base,
background: "#023950",
// match with the menu
borderRadius: state.isFocused ? "3px 3px 0 0" : 3,
// Overwrittes the different states of border
borderColor: state.isFocused ? "yellow" : "green",
// Removes weird border around container
boxShadow: state.isFocused ? null : null,
"&:hover": {
// Overwrittes the different states of border
borderColor: state.isFocused ? "red" : "blue"
}
}),
menu: base => ({
...base,
// override border radius to match the box
borderRadius: 0,
// beautify the word cut by adding a dash see https://caniuse.com/#search=hyphens for the compatibility
hyphens: "auto",
// kill the gap
marginTop: 0,
textAlign: "left",
// prevent menu to scroll y
wordWrap: "break-word"
}),
menuList: base => ({
...base,
// kill the white space on first and last option
padding: 0
})
};
Run Code Online (Sandbox Code Playgroud)
在过去的一个,作为选择应该是使用通过JS风格的className道具只能将一类外容器上提到这里。如果您真的想要,您仍然可以为组件添加前缀,classNamePrefix但它不会真正帮助您进行样式设置。
| 归档时间: |
|
| 查看次数: |
11898 次 |
| 最近记录: |