Material-ui: Autocomplete incompatibility with InputProps.

Created on 24 Feb 2020  路  1Comment  路  Source: mui-org/material-ui

  • [ ] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

Autocomplete element stop working after adding 'InputProps' prop to the TextField.

Expected Behavior 馃

I want to render Autocomplete with custom 'startAdornment'

Code Example 馃暪

const AppSelectAutocomplete = () => {
  const classes = useStyles();
  const [state, setState] = React.useState(null);

  return (
    <Autocomplete
      // open
      freeSolo
      selectOnFocus
      autoHighlight
      value={state}
      loading={false}
      options={countries}
      style={{ width: 500 }}
      onChange={(e, option) => setState(option)}
      className="AutocompleteLocation"
      classes={{ option: classes.option }}
      getOptionLabel={option => option.app_name}
      renderOption={option => (
        <div className="AutocompleteLocation-dropdown">
          <span className="app-logo">
            <img src={option.img} alt={option.app_name} />
          </span>
          <div className="AutocompleteLocation-text">
            <span className="app-name">{option.app_name}</span>
            <span className="app-publisher">{option.publisher}</span>
          </div>
        </div>
      )}
      renderInput={params => {
        return (
          <TextField
            {...params}
            placeholder="Aplication name"
            variant="outlined"
            InputProps={{ startAdornment: 's' }} // ??????? If enable this prop Autocomplete will stop working
            inputProps={{
              ...params.inputProps,
              autoComplete: 'new-password'
            }}
          />
        );
      }}
    />
  );
};

Context 馃敠

I want to render Autocomplete with custom 'startAdornment'

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.9.3 |
| React | v16.12.0 |
| Browser | Chrome |

Most helpful comment

I found out the reason. It's because I didn't pass ...params.InputProps to InputProps... 馃槗
It should be like this: InputProps={{ ...params.InputProps, startAdornment: <div/>}}

>All comments

I found out the reason. It's because I didn't pass ...params.InputProps to InputProps... 馃槗
It should be like this: InputProps={{ ...params.InputProps, startAdornment: <div/>}}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattmiddlesworth picture mattmiddlesworth  路  3Comments

FranBran picture FranBran  路  3Comments

TimoRuetten picture TimoRuetten  路  3Comments

newoga picture newoga  路  3Comments

ryanflorence picture ryanflorence  路  3Comments