Although this question is not recent, I encountered the same issue and managed to find a effective solution which I would like to share here.
The code you are currently using is missing two crucial elements: the marginThreshold
property and a maxWidth
style. The marginThreshold
determines how close to the window edge the popover can be displayed. Additionally, including the maxWidth
style ensures that the menu stretches across the full width as intended.
Below is the updated version of your menu component:
<Menu
position="relative"
id="basic-menu"
anchorEl={anchorEl}
open={open}
onClose={handleClose}
marginThreshold={0}
slotProps={{
paper: {
sx: {
color: 'red',
width: '100%',
maxWidth: '100%',
left: '0px',
right: '0px',
},
}
}}
MenuListProps={{
'aria-labelledby': 'basic-button',
}}
>
In addition to addressing the above issues, it's worth noting that the PaperProps
attribute has been deprecated. As a replacement, I've switched to utilizing the new slotProps
pattern.