With a select TextField that has a label and null initial value, when focus is lost the selected value will overlap the label. This only happens if the initial value is null, if it is a blank string the issue does not occur.
TextField's selected value should not overlap the label when focus is lost.
TextField's selected value overlaps the label when focus is lost.
Link: https://codesandbox.io/s/wqp00361y7
I have a TextField select component whose initial value is null, not a blank string.
| Tech | Version |
|--------------|---------|
| Material-UI | v3.1.1 |
| React | 16.4.1 |
| Browser | Chrome Version 69.0.3497.100 (Official Build) (64-bit) |
| TypeScript | No |
| etc. | Windows 7 64-bit |
TextField values should not be null
Use InputLabelProps as props_
<TextField select InputLabelProps={{shrink:this.state.value?true:false}} value={this.state.value} onChange={this.handleChange} >
{options.map(data=>{
*iterate options )}
</TextField>
use onChange to setState value
@Dileep9999 's solution fixed it for me, but just wanted to add you can tighten up the ternary.
Instead of
InputLabelProps={{ shrink: this.state.value ? true: false }}
use
InputLabelProps={{ shrink: !!this.state.value }}
@Dileep9999 's solution fixed it for me, but just wanted to add you can tighten up the ternary.
Instead of
InputLabelProps={{ shrink: this.state.value ? true: false }}
use
InputLabelProps={{ shrink: !!this.state.value }}
how can I leave 1000 likes and hearts for this comment? :) thanks!!!
Most helpful comment
@Dileep9999 's solution fixed it for me, but just wanted to add you can tighten up the ternary.
Instead of
InputLabelProps={{ shrink: this.state.value ? true: false }}
use
InputLabelProps={{ shrink: !!this.state.value }}