diff --git a/src/components/File/NewNote.tsx b/src/components/File/NewNote.tsx index 2ada1cfb..da0e3a23 100644 --- a/src/components/File/NewNote.tsx +++ b/src/components/File/NewNote.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useRef, useEffect } from "react"; interface NewNoteComponentProps { onFileSelect: (path: string) => void; @@ -12,6 +12,20 @@ const NewNoteComponent: React.FC = ({ onClose, }) => { const [fileName, setFileName] = useState(""); + const modalRef = useRef(null); + + const handleOffClick = (event: MouseEvent) => { + if (modalRef.current && !modalRef.current.contains(event.target as Node)) { + onClose(); + } + }; + + useEffect(() => { + document.addEventListener("mousedown", handleOffClick); + return () => { + document.removeEventListener("mousedown", handleOffClick); + }; + }, [onClose]); const sendNewNoteMsg = async () => { const notePath = await window.files.joinPath( @@ -24,7 +38,7 @@ const NewNoteComponent: React.FC = ({ onClose(); // Close modal after file creation }; - const handleKeyPress = (e: React.KeyboardEvent) => { + const handleKeyPress = (e: React.KeyboardEvent) => { if (e.key === "Enter") { sendNewNoteMsg(); } @@ -35,8 +49,11 @@ const NewNoteComponent: React.FC = ({ } return ( -
-
+
+

Create New Note