Material-ui: [Autocomplete] Customize popper width

Created on 24 Jan 2020  路  2Comments  路  Source: mui-org/material-ui

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Summary 馃挕

Currently, the PopperComponent width is always set to anchorEl.clientWidth (see https://github.com/mui-org/material-ui/blob/master/packages/material-ui-lab/src/Autocomplete/Autocomplete.js#L440-L442). I would like to be able to customize that so the dropdown can be a different width. It would probably make sense to also expose the placement of the popper. I'm not sure if it makes more sense to just expose PopperProps -- I saw in this issue that you're not the biggest fan of that approach: https://github.com/mui-org/material-ui/issues/18885#issuecomment-566494202

Examples 馃寛

The search box on the material-ui docs is an example of where the dropdown is a different width than
image

Motivation 馃敠

I have content in my dropdown that is wider than the search box and it currently has an annoying wrap. Also, having the textbox width expand with css like in the material-ui documentation can result in a mis-aligned and too-small popper.

Autocomplete question

Most helpful comment

This worked for me:

const PopperMy = function (props) {
  return (<Popper {...props} style={{ width: 250 }} placement='bottom-start' />)
}

then

<Autocomplete PopperComponent={PopperMy}>

All 2 comments

You can provide a custom PopperComponent prop to change the positioning logic.

This worked for me:

const PopperMy = function (props) {
  return (<Popper {...props} style={{ width: 250 }} placement='bottom-start' />)
}

then

<Autocomplete PopperComponent={PopperMy}>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

ericraffin picture ericraffin  路  3Comments

newoga picture newoga  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

revskill10 picture revskill10  路  3Comments

rbozan picture rbozan  路  3Comments