Skip to content

Commit 2b37ead

Browse files
committed
fixed menu button not closing the drop down menu
1 parent d0e3464 commit 2b37ead

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

app/src/components/top/NavBar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useRef, useState } from 'react';
22
import { Link } from 'react-router-dom';
33
import Avatar from '@mui/material/Avatar';
44
import Button from '@mui/material/Button';
@@ -26,11 +26,14 @@ const NavBar = () => {
2626
);
2727

2828
const dispatch = useDispatch();
29+
const menuButtonRef = useRef(null);
2930

3031
useEffect(()=>{
3132
setProjectName(state.name)
3233
}, [state.name])//update the ProjectName after state.name changes due to loading projects
3334

35+
36+
3437
const buttonContainerStyle = {
3538
display: 'flex',
3639
alignItems: 'center',
@@ -129,13 +132,15 @@ const NavBar = () => {
129132
style={moreVertButtonStyle}
130133
variant="contained"
131134
color="primary"
132-
onClick={() => setDropMenu((prevDropMenu) => !prevDropMenu)}
135+
onClick={() => setDropMenu(!dropMenu)}
136+
ref={menuButtonRef}
133137
>
134138
<MoreVertIcon style={{ color: 'white' }} />
135139
</Button>
136140
<NavBarButtons
137141
dropMenu={dropMenu}
138142
setDropMenu={setDropMenu}
143+
menuButtonRef={menuButtonRef}
139144
style={{ color: 'white' }}
140145
/>
141146
</div>

app/src/components/top/NavBarButtons.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,9 @@ function navbarDropDown(props) {
302302
const handleClick = (event) => {
303303
if (event.type === "click" &&
304304
(dropdownRef.current &&
305-
!dropdownRef.current.contains(event.target)) || event.type === "message" && event.data === 'iframeClicked'
305+
!dropdownRef.current.contains(event.target) && !props.menuButtonRef.current.contains(event.target)) || event.type === "message" && event.data === 'iframeClicked'
306306
) {
307+
//menuButtonRef is to ensure that handleClose does not get invoked when the user clicks on the menu dropdown button
307308
handleClose();
308309
}
309310
};
@@ -388,10 +389,11 @@ function navbarDropDown(props) {
388389
width="16"
389390
height="16"
390391
fill="currentColor"
391-
className="bi bi-book"
392+
className="bi bi-bag-check"
392393
viewBox="0 0 16 16"
393394
>
394-
<path d="M1 2.828c.885-.37 2.154-.769 3.388-.893 1.33-.134 2.458.063 3.112.752v9.746c-.935-.53-2.12-.603-3.213-.493-1.18.12-2.37.461-3.287.811V2.828zm7.5-.141c.654-.689 1.782-.886 3.112-.752 1.234.124 2.503.523 3.388.893v9.923c-.918-.35-2.107-.692-3.287-.81-1.094-.111-2.278-.039-3.213.492V2.687zM8 1.783C7.015.936 5.587.81 4.287.94c-1.514.153-3.042.672-3.994 1.105A.5.5 0 0 0 0 2.5v11a.5.5 0 0 0 .707.455c.882-.4 2.303-.881 3.68-1.02 1.409-.142 2.59.087 3.223.877a.5.5 0 0 0 .78 0c.633-.79 1.814-1.019 3.222-.877 1.378.139 2.8.62 3.681 1.02A.5.5 0 0 0 16 13.5v-11a.5.5 0 0 0-.293-.455c-.952-.433-2.48-.952-3.994-1.105C10.413.809 8.985.936 8 1.783z" />
395+
<path fillRule="evenodd" d="M10.854 8.146a.5.5 0 0 1 0 .708l-3 3a.5.5 0 0 1-.708 0l-1.5-1.5a.5.5 0 0 1 .708-.708L7.5 10.793l2.646-2.647a.5.5 0 0 1 .708 0z"/>
396+
<path d="M8 1a2.5 2.5 0 0 1 2.5 2.5V4h-5v-.5A2.5 2.5 0 0 1 8 1zm3.5 3v-.5a3.5 3.5 0 1 0-7 0V4H1v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V4h-3.5zM2 5h12v9a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V5z"/>
395397
</svg>
396398
</button>
397399
</Link>

0 commit comments

Comments
 (0)