question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Autocomplete] How to customize the popper width?

See original GitHub issue
  • 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:

https://github.com/mui/material-ui/blob/ae87437fc6345b95c991c6e392eaf9f9a0f356e1/packages/mui-material/src/Autocomplete/Autocomplete.js#L597

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

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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

82reactions
k2scommented, May 24, 2022

This worked for me (as a new component created outside of a render function):

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

then

<Autocomplete PopperComponent={PopperMy}>
27reactions
oliviertassinaricommented, May 24, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I change the width of Material UI Autocomplete ...
4 Answers 4 · Define a custom Popper : const PopperMy = function (props) { return <Popper {... · In Popper style, set...
Read more >
How to Style the Material-UI Autocomplete Component
There are two Autocomplete subcomponents that can have custom width: Input field width; Popper component width. MUI Autocomplete Input Width.
Read more >
Popper in Autocomplete - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
How can I change the width of Material UI Autocomplete ...
To have a dynamic menu based on elements inside the menu itself you have to customize the Autocomplete's PopperComponent property in this way:....
Read more >
Popper API - Material UI - MUI
Name Type Default open * bool false anchorEl HTML element | object | func children node | func
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found