I have a TextField for phone numbers in a short form. And then i want to mask this form field like (0)xxx xxx xx xx.
I'm trying to use react-input-mask plugin with Material-UI. But if i want to change input value, this is not updating the my main TextField.
<TextField
ref="phone"
name="phone"
type="text"
value={this.state.phone}
onChange={this.onChange}
>
<InputMask value={this.state.phone} onChange={this.onChange} mask="(0)999 999 99 99" maskChar=" " />
</TextField>
Actually, I couldn't find any documentation for masking with Material-UI. I'm trying to figure out how can i use with another plugins.
Question:
Work Around:
You can controll Label Position with "floatingLabelFixed" prop. At your handleChange look to state input value.
...when create with value:
...when edit (onChange):
...your input:
Update
versions: material-ui 0.20.2, react-input-mask 2.0.4
Seems like the API changed a bit:
Demo
Original
This should do the trick:
Demo:
This is valid for current version of
react-input-mask
andmaterial-ui
:For current version of Material-UI and react-input-mask, the following answer worked: