Before my question is marked as duplicate, I want to clarify I know how to write a controlled input in vanilla/regular React.
The issue I have now is that I expected to be able to do the same thing with React-Admin's TextInput
. Using typescript hints, I see that value
and onChange
are accepted as properties, but they don't control the input.
E.g.
const LowerCaseInput: React.FC = (props) => {
const [value, setValue] = useState('');
const handleChange = (event: any) => {
const val = event.target.value || '';
setValue(val.toLowerCase()) // Disallow Uppercase characters
}
return <TextInput {...props} value={value} onChange={handleChange} />
}
In this example, I can type characters into the TextInput but they are not coerced to lower case. I can console.log() the values and those show up every time I type. Also, switching to a vanilla <input />
allows it to be controlled, i.e. the values are lower case.
Am I supposed to be able to control inputs this way, or is there some other (roundabout method) of doing something fairly standard?