Am using React and material UI to display an outlined input. I can make it display that there has been an error with the error prop set to true but there is an issue when i try to add helperText and my message as a prop:
<OutlinedInput
margin="dense"
value=""
placeholder="my placeholder"
error
helperText="There has been an error" // Property 'helperText' does not exist on type 'IntrinsicAttributes & OutlinedInputProps'
/>
Is there any way to use both an OutlinedInput and display an error helper message?
You can use FormHelperText component from @material-ui/core.
const [accountId, setAccountId] = useState({ value: "", error: "" });
<FormControl variant="outlined">
<InputLabel htmlFor="accountId">Account Id</InputLabel>
<OutlinedInput
value={accountId.value}
onChange={(e) => setAccountId({value: e.target.value, error:""})}
inputProps={{
"aria-label": "Account Id",
}}
labelWidth={74}
error={!!accountId.error}
/>
{!!accountId.error && (
<FormHelperText error id="accountId-error">
{accountId.error}
</FormHelperText>
)}
</FormControl>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With