简体   繁体   中英

React TypeScript with Material UI

I would like to ask for help. How can I be able to render these menus under their correct and proper category menu? Currently, they would just pile against each other instead of rendering from their proper menu. I am using React together with TypeScript and I have been working for this nonstop and haven't found an answer. Hope someone could help.

This is a sample photo of the problem. They're all overlapping and rendering together instead of rendering it differently from the other menu.

在此处输入图像描述

  • This Message Menu would only render a Menu List drop down menu.

在此处输入图像描述

  • This Operation Menu would and should only render Ack, Unack, Clear, and Comment

Here's my source code.

const handleClick = (index: null, event: React.MouseEvent<HTMLButtonElement>) => {
  setAnchorEl(event.currentTarget);
};

<Menu
  id="basic-menu"
  anchorEl={anchorEl}
  open={open}
  onClose={handleClose}
  MenuListProps={{
    "aria-labelledby": "basic-button",
  }}
>
  {customtoolinfo.menu_sub.map((custommenusubtool: any) => (
    <MenuItem onClick={handleClose}>
      {custommenusubtool.menu_sub_name}
    </MenuItem>
  ))}
</Menu>

The issue is because you have same anchorEl value of all sub menus. This issue can be fixed in many ways. One way is to have only one menu and render it's sub-menus based on condition or second way is to have different anchorEl state for every submenu and control them based on menu

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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