Skip to content

Commit

Permalink
Merge pull request #68 from apsinghdev/fix/hide-menu-on-click
Browse files Browse the repository at this point in the history
fix: hide menu when user click anywhere in canvas
  • Loading branch information
apsinghdev authored Sep 5, 2024
2 parents 02d06ab + 0383f14 commit b79acd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ function App() {
}
}, []);

// Hook to hide the menu when user click elsewhere on the screen
useEffect(() => {
const canvas = document.getElementById("canvas");
canvas.addEventListener("click", () => {
console.log("clicked");
if (showMenu) {
setShowMenu(false);
}
})
}, [showMenu]);

return (
<div id="container">
<Sidebar
Expand Down
1 change: 1 addition & 0 deletions client/src/components/Canvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Canvas(props){
className="h-full w-86vw"
style={{backgroundColor: `${canvasColor}`}}
ref={props.canvasRef}
id="canvas"
></canvas>
{props.showMenu && <Menu></Menu>}
</div>
Expand Down

0 comments on commit b79acd7

Please sign in to comment.