Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a Textfield in Material UI when used with Formik

I have a resulable Material UI textfield that I am using with my formik form -

<Fieldname="reportType"
    label="Report Type"
    disabled
    as={TextFieldOutLined}
/>

I want to make my reportType disabled. When I am passing disabled like above to my TextFieldOutLined it is not working.

Below is my TextFieldOutLined snippet.

const TextFieldOutLined = ({ label, disabled, ...props }) => {
    const classes = useStyles();

    const [field] = useField(props);
    return (
        <TextField
            className={classes.formControl}
            {...field}
            {...disabled}
like image 639
Pushpendra Yadav Avatar asked Sep 16 '25 05:09

Pushpendra Yadav


1 Answers

You should pass disabled={disabled} to your TextField component to disable your TextField when the value of disabled prop is truthy.

<TextField
    className={classes.formControl}
    {...field}
    disabled={disabled}
like image 144
Michael Avatar answered Sep 17 '25 19:09

Michael