【发布时间】:2018-12-15 10:13:18
【问题描述】:
使用react-select@next 并遵循示例here 自定义Control 组件不会产生预期的结果。
import TextField from "@material-ui/core/TextField";
import Select from "react-select";
const InputComponent = (props) => {
return (
<TextField {...props} />
);
};
export const MaterialSelect = (props) => {
const { suggestions, ...other } = props;
return (
<Select
options={suggestions}
components={{
Control: InputComponent,
}}
{...other}
/>
);
};
const suggestions = [
{
label: "Test One",
value: "testOne",
},
{
label: "Test Two",
value: "testTwo",
},
];
<MaterialSelect suggestions={suggestions} />
使用 Material-UI TextField 不会打开下拉菜单或显示任何装饰。我还尝试将{...props.selectProps} 而不是{...props} 传递给TextField,但没有成功
我还尝试使用 InputProps 属性为 TextField 单独传递组件,但没有成功。在我的Select 组件上使用menuIsOpen 可以按预期呈现菜单,但是输入TextField 不会产生任何结果、没有装饰等。
【问题讨论】:
标签: javascript reactjs material-design material-ui react-select