Skip to content

Commit b79acd7

Browse files
authored
Merge pull request #68 from apsinghdev/fix/hide-menu-on-click
fix: hide menu when user click anywhere in canvas
2 parents 02d06ab + 0383f14 commit b79acd7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

client/src/App.jsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,17 @@ function App() {
250250
}
251251
}, []);
252252

253+
// Hook to hide the menu when user click elsewhere on the screen
254+
useEffect(() => {
255+
const canvas = document.getElementById("canvas");
256+
canvas.addEventListener("click", () => {
257+
console.log("clicked");
258+
if (showMenu) {
259+
setShowMenu(false);
260+
}
261+
})
262+
}, [showMenu]);
263+
253264
return (
254265
<div id="container">
255266
<Sidebar

client/src/components/Canvas.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ function Canvas(props){
1111
className="h-full w-86vw"
1212
style={{backgroundColor: `${canvasColor}`}}
1313
ref={props.canvasRef}
14+
id="canvas"
1415
></canvas>
1516
{props.showMenu && <Menu></Menu>}
1617
</div>

0 commit comments

Comments
 (0)