[英]How do I limit possible inputs of String field in TextField component of Material-UI?
In HTML5 we can do <input type="text" maxlength="3" />
but how do I same in Material-UI ?在 HTML5 中,我们可以做<input type="text" maxlength="3" />
但我如何在 Material-UI 中做到这一点? Bellow is example Material-UI TextFiled component波纹管是示例 Material-UI TextFiled 组件
<TextField
id="name"
label="Name"
type="string"
//maxLength="3" Or maxlength="3" Or max="3"
margin="normal"
/>
Add the inputProps
to the TextField
example following:将inputProps
添加到TextField
示例中,如下所示:
<TextField
inputProps={{
maxLength: 10,
}}
/>
Or alternative hard coded solution:或替代硬编码解决方案:
<TextField
onInput={e => {
e.target.value = Math.max(0, parseInt(e.target.value)).toString().slice(0, 12);
}}
/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.