I noticed this when upgrading from Material UI 4.2.0 to 4.9.10, but through troubleshooting, I believe this behavior started with version 4.8.3
When using a Select with the multiple attribute, the popup menu moves upon selection of the first item. I have other examples where it moved several times as multiple items are selected, but in the example I'm providing here, it seems to just happen when choosing the first item. Here's a codesandbox demonstrating this: https://codesandbox.io/s/recursing-morse-2omxy?fontsize=14&hidenavigation=1&theme=dark
Here's the same code sample, but using Material UI 4.8.2. When I choose items from this example, the menu remains anchored to where it was when it popped up: https://codesandbox.io/s/recursing-frost-pxlds?fontsize=14&hidenavigation=1&theme=dark
My preferred behavior here is the second example, where the menu doesn't jump around on me as I'm selecting. I've looked through the API, and have tried specifying different anchors, but so far have not been able to keep the popup menu from moving around. Does anyone know of how to keep the menu in place with version 4.8.3 and beyond?
However, it can also take numeric horizontal and vertical values. 0, 0 positioning with anchorOrigin will set the Popover at the top left corner of the anchorEl element. The transformOrigin prop will flip which side of the Popover is adjacent to the anchorEl or anchorPosition coordinates.
The component is built on top of the Modal component. The scroll and click away are blocked unlike with the Popper component. Use the radio buttons to adjust the anchorOrigin and transformOrigin positions. You can also set the anchorReference to anchorPosition or anchorEl .
The anchorEl prop is optional and take a component or element. If no element is passed, it will default to the topmost parent element of the Popover (probably not what you want).
When anchorReference is toggled via button click, the component consumes the appropriate props and ignores props it doesn’t need.
Turns out that this is a Material UI bug that's targeted to be fixed in version 5. Here is a workaround until then:
<Select
MenuProps={{
getContentAnchorEl: () => null,
}}
@JoshSchmitton's answer did not work for me with Typescript as the type for getContentAnchorEl is ((element: Element) => Element) | null | undefined
However the following slight modification achieves the desired result:
<Select
MenuProps={{
getContentAnchorEl: null,
}} />
Thank you Josh Schmitton
You can create object:
const MenuProps = {
getContentAnchorEl: null,
PaperProps: {
style: {
maxHeight: 200,
width: 300,
},
},
};
and then
<Select MenuProps={MenuProps}>
Try the following code, the result will be nearly the same with current version 5 material UI.
getContentAnchorEl
to null
is used to fix the drop-down's position.
And the rest of the props is used for move the drop-down lower but not overlap with the input field.
<Select
MenuProps={{
getContentAnchorEl: () => null,
anchorOrigin: { vertical: 'bottom', horienter code herezontal: 'center' },
transformOrigin: { vertical: 'top', horizontal: 'center' },
}} />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With