I have an <input>
tag of type=number
, and I would like to disable keyboard input in order to force the user to change the value with the spinner (up and down arrows). I am consuming the input value on every change, so I want to do this so that I don't have to validate user input in real-time, which seems like the only alternative.
Outside of vanilla html and javascript, I would also like to know how to do this in react and material-ui. If I have something like the following, how can I prevent keyboard input?
const [value, setValue] = useState(10);
return (
<React.Fragment>
<TextField
name=name
type=number
label=label
inputProps={{
min: 0,
max: 100,
step: 2,
}}
defaultValue={value}
onChange={(event) => {
setValue(Number(event.target.value));
}}
/>
</React.Fragment>
);