Here is a screenshot of the issue:
I am designing the UI for a web app I am working on with React and Material UI for the mobile orientation. I have been trying to get the sidebar menu to appear starting from the leftmost part of the screen, and there seems to be some sort of margin that won’t let the left part of the menu start from the left edge. It starts a few pixels after. What can I do?
Here’s a piece of my code for reference:
<Menu
className='menu-style'
anchorReference="anchorPosition"
anchorPosition = {{top: 90, left: 0}}
anchorOrigin={{vertical: 'top', horizontal: 'left'}}
transformOrigin={{vertical: 'top', horizontal: 'left'}}
anchorEl={null}
open={isOpen}
onClose={() => setIsOpen(false)}
PaperProps={{
style: {
width: '80vw',
margin: '0 !important',
height: '100vh',
},
}}
>
<MenuItem onClick={() => setIsOpen(false)}>
<a href='#'>Buy</a>
</MenuItem>
</Menu>
I have tried setting the margins to 0 with the paper props style but it’s not responding to it. The dropdown menu still starts a few pixels after the left, instead of from the leftmost part. No parent components have any margins added to them either.
2
Answers
I think you need to pass styles to
sx
property, notPaperProps > style
.For example:
Would a
Drawer
be a better component in your use case?With that aside, you can use the
sx
prop or thestyled
functionality combined with the provided class definitionmenuClasses
to position the menu statically.The
!important
is required as you are fightingpopper
which is attempting to dynamically position your menu by assigningleft
andtop
as a direct style.