单击按钮时菜单未关闭

时间:2019-12-11 02:18:29

标签: reactjs material-ui

当我单击下面的按钮时,任何人都无法解决此菜单的帮助

    <IconButton
              aria-haspopup="true"
              color="inherit"
              className={classes.headerMenuButton}
              aria-controls="profile-menu"
              onClick={e => setProfileMenu(e.currentTarget)}

            >
              <AccountIcon  />

            </IconButton>

            <Menu
              id="profile-menu"
              open={Boolean(profileMenu)}
              anchorEl={profileMenu}
              onClose={() => setProfileMenu(null)}
              className={classes.headerMenu}
              classes={{ paper: classes.profileMenu }}
              disableAutoFocusItem
            >
              <div className={classes.profileMenuUser}>
                {profileData === undefined && (
                  <CircularProgress className={classes.progress} />
                )}
                {profileData !== undefined && (
                  <Typography variant="h4" weight="medium">
                    {profileData.fullName}
                  </Typography>
                )}
              </div>
              <MenuItem
                className={classNames(
                  classes.profileMenuItem,
                  classes.headerMenuItem,
                )}
                component={RouterLink}
                onClick={() => setProfileMenu(null)}
                to="/app/profile/changepassword"
              >
                <AccountIcon className={classes.profileMenuIcon} /> Change Password
              </MenuItem>
              <MenuItem
                className={classNames(
                  classes.profileMenuItem,
                  classes.headerMenuItem,
                )}
                component={RouterLink}
                onClick={() => setProfileMenu(null)}
                to="/app/profile/changeprofile"
              >
                <AccountIcon className={classes.profileMenuIcon} /> Edit Profile
              </MenuItem>
              <div className={classes.profileMenuUser}>
                <Typography
                  className={classes.profileMenuLink}
                  color="primary"
                  onClick={() => signOut(userDispatch, props.history)}
                >
                  Sign Out
                </Typography>
              </div>
            </Menu>

1 个答案:

答案 0 :(得分:0)

单击按钮时,如果菜单已经打开,则关闭

<IconButton
          aria-haspopup="true"
          color="inherit"
          className={classes.headerMenuButton}
          aria-controls="profile-menu"
          onClick={e => setProfileMenu( profileMenu ? null : e.currentTarget)}
        >