【发布时间】:2020-09-18 10:38:15
【问题描述】:
我正在关注https://material-ui.com/components/autocomplete/ 中的各种示例来创建自定义自动完成功能。我正在尝试使用 renderInput 属性来使用自定义输入组件。我发现的所有示例都使用TextField 组件,但我想使用常规的input 组件。
问题是,选项永远不会显示。我在这里创建了一个演示(将renderInput 与renderInputWORKING 交换以查看工作版本):
https://codesandbox.io/s/epic-johnson-oxy7b?file=/src/App.tsx
在renderInput中使用以下代码:
const renderInput = (params: AutocompleteRenderInputParams) => {
console.log(params);
const { InputLabelProps, inputProps, InputProps } = params;
return (
<div>
<label {...InputLabelProps}>foo</label>
<input {...InputProps} {...inputProps} />
</div>
);
};
如何在<Autocomplete /> 上使用<input /> 组件作为renderInput 属性?
【问题讨论】:
标签: reactjs autocomplete material-ui