Material-UI Autocomplete move clear and popup Icon location to the left

Viewed 65

We try to implement the autocomplete text field. The clear and popup icon always appears from the right side (end adornment).

We have an option to work with rtl direction and we can't find a way to flip this component:

  1. put the clear/popup icon in the start adornment.
  2. change the direction that will set the end adornment to the left side of the field

Is anyone found a way to do this?

1 Answers

The clear and popup icon buttons of Autocomplete is hardcoded in endAdornment prop, there is no way to change that using the public API, but you can swap it by using this workaround:

export default function Demo() {
  return (
    <Autocomplete
      options={top100Films.map((option) => option.title)}
      renderInput={(params) => {
        return (
          <TextField
            {...params}
            InputProps={{
              ...params.InputProps,
              startAdornment: (
                <div>{params.InputProps.endAdornment.props.children}</div>
              ),
              endAdornment: null
            }}
            label="freeSolo"
          />
        );
      }}
    />
  );
}

Live Demo

Codesandbox Demo

Related