Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material Autocomplete does not work with InputProps

I am trying to change the border of my TextField that is rendered through my Autocomplete, but when I add the InputProps prop, the Autocomplete no longer renders Chips

<Autocomplete
    multiple
    freeSolo
    options={options}
    renderTags={(value, { className, onDelete }) =>
        value.map((option, index) => (
            <Chip
                key={index}
                variant="outlined"
                data-tag-index={index}
                tabIndex={-1}
                label={option}
                className={className}
                color="secondary"
                onDelete={onDelete}
            />
        ))
    }
    renderInput={(params) => (
        <TextField
            {...params}
            id={id}
            className={textFieldStyles.searchField}
            label={label}
            value={value}
            onChange={onChange}
            variant="outlined"
            //InputProps={{
            //     classes: {
            //         input: textFieldStyles.input,
            //         notchedOutline: textFieldStyles.notchedOutline
            //     }
            //}}
            InputLabelProps={{
                classes: {
                    root: textFieldStyles.label
                }
            }}
        />
    )}
/>

The above code works, and once I uncomment the InputProps line, the input no longer renders Chips when an item is selected or entered.

Thanks

like image 557
Arthur Avatar asked Nov 10 '19 17:11

Arthur


1 Answers

This happens because the InputProps attribute is overriding the InputProps parameter of params, you have to merge InputProps property of params:

InputProps={{
    ...params.InputProps,
    classes: {
        input: textFieldStyles.input,
        notchedOutline: textFieldStyles.notchedOutline
    }
}}
like image 175
Heldev Avatar answered Oct 22 '22 15:10

Heldev