6

how to disable autocomplete auto position?

want to show autocomplete options always bottom.

https://codesandbox.io/s/material-demo-forked-t1luy?file=/demo.js

Rahul Shah
  • 61
  • 1
  • 2
  • 6

5 Answers5

4

Add popper props with modifiers:

<Autocomplete
  id="combo-box-demo"
  options={top100Films}

  /* ...yourProps */

  componentsProps={{
    popper: {
      modifiers: [
        {
          name: 'flip',
          enabled: false
        },
        {
           name: 'preventOverflow',
           enabled: false
         }
      ]
    }
  }}

  renderInput={(params) => (
    <TextField {...params} label="Combo box" variant="outlined" />
  )}
/>
  • 2
    Thank you, finally a solution that works. **Note of others**: For this to work, I had to upgrade to the latest version of `@mui/material`, which as of now, is `5.14.2` – tsuki Jul 25 '23 at 12:27
2

For the current latest version of MaterialUI, you can use the property disablePortal to achieve behavior when a popup with a list of options will always be shown on the bottom

Should be something like this

<Autocomplete
  id="combo-box-demo"
  options={top100Films}
  getOptionLabel={(option) => option.title}
  style={{ width: 300, paddingTop: 300 }}

  disablePortal={true}

  renderInput={(params) => (
    <TextField {...params} label="Combo box" variant="outlined" />
  )}
/>
Georgiy Dubrov
  • 408
  • 2
  • 7
2

property disablePortal={true} works for me.

1

For MUI v5, if you're trying to use the "disablePortal" prop, as it should work on previous versions of MUI, what worked for me is to simply remove the "disablePortal" prop, which automatically set the placement of the dropdown list to "bottom" for any number of elements in the list.

Caio Amorim
  • 165
  • 6
0

You can do it with flexbox

You can wrap your Autocomplete component with a div and add the below style

    <div style={{display: 'flex', alignItems: 'flex-end'}}>
        <Autocomplete
          id="combo-box-demo"
          options={top100Films}
          getOptionLabel={(option) => option.title}
          style={{ width: 300}}
          renderInput={(params) => (
            <TextField {...params} label="Combo box" variant="outlined" />
          )}
        />
    </div>
gikall
  • 559
  • 5
  • 16