我是新来的实质性用户界面。我想要自动完成组件的浮动标签。但是从自动完成选项标签中选择任何值后,标签应贴在顶部。请转到codeandbox查看实际问题。
提前致谢
选择后,您需要更新select元素的属性。为此,我使用的是state shrink
,它false
最初true
是在选择项目后设置的。如果状态shrink
为true
,则InputLabelProps
设置为{shrink: true}
。否则,将设置空对象。
state = {
single: null,
multi: null,
shrink:false //Newly added
};
handleChange = name => value => {
this.setState({
[name]: value
});
this.setState({shrink:true}); //Newly added
};
<Select
classes={classes}
styles={selectStyles}
options={suggestions}
components={components}
value={this.state.single}
onChange={this.handleChange("single")}
placeholder="Search a country (start with a)"
textFieldProps={{
label: "Label",
InputLabelProps: this.state.shrink?{shrink:true}:{} //Modified line
}}
/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句