我使用的是react-select和TextField Material-UI。是否可以像在TextField中一样在react-select中设置helperText (组件下面的小文本
提前感谢您的帮助。
附言:我不认为我的问题是this question的重复。另一篇文章是关于如何自定义组件,这是react-select的一部分,我想添加一个react-select没有的选项。
发布于 2019-02-28 21:53:59
你是说占位符吗?我认为你可以这样设置:
const MyComponent = () => (
<Select placeholder="Select..." options={options} />
)但是,如果您想要相同的外观,为什么要使用来自不同库的控件。我认为你可以在Select from Material-Ui中使用FormHelperText。因此,您最好使用此select,而不是react-select。
<FormControl className={classes.formControl}>
<InputLabel shrink htmlFor="age-native-label-placeholder">
Age
</InputLabel>
<NativeSelect
value={this.state.age}
onChange={this.handleChange('age')}
input={<Input name="age" id="age-native-label-placeholder" />}
>
<option value="">None</option>
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</NativeSelect>
<FormHelperText>Label + placeholder</FormHelperText>
</FormControl>发布于 2019-02-28 23:14:27
TextField主要是包括FormHelperText在内的几个低级组件的便捷包装器。
下面是Material-UI文档中使用react-select:https://material-ui.com/demos/autocomplete/#react-select的自动完成演示
以下是使用FormHelperText:https://codesandbox.io/s/rynvn8po5p演示程序的修改版本
下面是该代码的相关代码片段:
<Select
classes={classes}
styles={selectStyles}
options={suggestions}
components={components}
value={this.state.single}
onChange={this.handleChange("single")}
placeholder="Search a country (start with a)"
isClearable
/>
<FormHelperText>Here's my helper text</FormHelperText>精选的Material-UI演示还展示了许多不使用TextField而使用FormHelperText的示例:https://material-ui.com/demos/selects/#simple-select
下面是FormHelperText的API文档:https://material-ui.com/api/form-helper-text/
https://stackoverflow.com/questions/54926826
复制相似问题