简体   繁体   English

如何在按钮左下角制作 Material UI 菜单下拉菜单

[英]How to make the Material UI menu dropdown at the bottom left of the button

I hope you guys are doing well: This is my code sandbox: https://codesandbox.io/s/hungry-agnesi-vn6039?file=/demo.tsx我希望你们做得很好:这是我的代码沙箱: https://codesandbox.io/s/hungry-agnesi-vn6039?file=/demo.tsx

I currently want to have the Material UI menu drop down below starting at the exact bottom left of the button.我目前想让 Material UI 菜单从按钮的左下角开始下拉。 However, as visible in my code sandbox, the menu starts a little bit right of the desired spot I want.但是,正如在我的代码沙箱中可见的那样,菜单从我想要的所需位置开始一点点。 Is there a way for me to start the dropdown menu at the bottom left of the button?有没有办法让我在按钮左下角启动下拉菜单? I really appreciate any responses!我真的很感激任何回应!

Thanks!谢谢!

Give you button a little margin from left.给你按钮从左边一点边距。 在此处输入图像描述

You can add negative marginLeft in your dropdown like this.您可以像这样在下拉列表中添加负 marginLeft。 Here is the working codesandbox这是工作代码和

      <Menu
        id="basic-menu"
        anchorEl={anchorEl}
        open={open}
        onClose={handleClose}
        anchorOrigin={{
          vertical: "bottom",
          horizontal: "left"
        }}
        transformOrigin={{
          vertical: "top",
          horizontal: "left"
        }}
        MenuListProps={{
          "aria-labelledby": "basic-button"
        }}
        style={{ // Add here you negative margin
          marginLeft: "-8px"
        }}
      >

Let me know if it helps and if is ok for you to add the inline style.让我知道它是否有帮助,以及是否可以添加内联样式。 Or you can do the same by using a styled component.或者您可以通过使用样式组件来执行相同的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM