I am currently facing an issue with applying maxLength to the TextField component when the type is set to number.
Here is my code snippet:
const CustomTextField = ({
label,
value,
maxLength,
required,
disabled,
handleChange,
handleClear,
error,
helpertext,
shrink,
type,
placeholder
}) => {
return (
<TextField
label={label}
fullWidth
size='small'
variant='standard'
value={value}
type={type}
placeholder={placeholder}
inputProps={{ maxLength: (maxLength && parseInt(maxLength)) || 99}}
InputLabelProps={{ shrink: shrink, style: { fontSize: 18 } }}
required={required}
onChange={handleChange}
InputProps={{
endAdornment: (
(value?.length > 0 && !disabled) ? <IconButton onClick={handleClear}>
<ClearOutlinedIcon/>
</IconButton> : ''
),
readOnly: disabled
}}
error={error}
helperText={helpertext}
/>
)
}
CustomTextField.propTypes = {
disabled: PropTypes.bool.isRequired,
error: PropTypes.bool,
handleChange: PropTypes.func.isRequired,
handleClear: PropTypes.func.isRequired,
helpertext: PropTypes.string.isRequired,
label: PropTypes.string.isRequired,
maxLength: PropTypes.string,
placeholder: PropTypes.string,
required: PropTypes.bool.isRequired,
type: PropTypes.string,
value: PropTypes.string,
}