似乎你在努力让react select看起来像是材料。
假设我可以给你举个例子:
首先,你需要实现你的选择看起来像材料:
class Option extends React.Component {
handleClick = event => {
this.props.selectOption(this.props.data, event);
};
render() {
const { children, isFocused, isSelected, onFocus } = this.props;
console.log(this.props);
return (
<MenuItem
onFocus={onFocus}
selected={isFocused}
onClick={this.handleClick}
component="div"
style={{
fontWeight: isSelected ? 500 : 400
}}
>
{children}
</MenuItem>
);
}
}
然后需要包装react select并将其作为
输入组件
物料界面输入中的道具。
function SelectWrapped(props) {
const { classes, ...other } = props;
return (
<Select
components={{
Option: Option,
DropdownIndicator: ArrowDropDownIcon
}}
styles={customStyles}
isClearable={true}
{...other}
/>
);
}
然后将其用作:
<div className={classes.root}>
<Input
fullWidth
inputComponent={SelectWrapped}
value={this.state.value}
onChange={this.handleChange}
placeholder="Search your values"
id="react-select-single"
inputProps={{
options: testOptions
}}
/>
</div>
请注意,我在示例中将选项作为inputprops传递。
下面是一个工作示例:
https://codesandbox.io/s/nk2mkvx92p
请找到这些
自定义样式
在演示中,使您的组件具有更多的材质感觉。
希望这会是你。