Skip to content

Commit

Permalink
calling handle save when clicking outside of the editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tfhuhtal committed Oct 7, 2024
1 parent b10017a commit 381fa0e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion client/components/Generic/Textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const Textarea = ({
const viewOnly = useSelector(({ form }) => form.viewOnly)
const ref = useRef(null)
const [changes, setChanges] = useState(false)
const editorContainerRef = useRef(null)

const formData = useSelector(({ form }) => form.data)

Expand Down Expand Up @@ -230,8 +231,23 @@ const Textarea = ({
}
}
}

useEffect(() => {
const handleClickOutside = event => {
if (editorContainerRef.current && !editorContainerRef.current.contains(event.target)) {
handleSave()
}
}

// Bind the event listener to the document
document.addEventListener('mousedown', handleClickOutside)
return () => {
// Cleanup the event listener on component unmount
document.removeEventListener('mousedown', handleClickOutside)
}
}, [editorContainerRef, handleSave])
return (
<div data-cy={`textarea-${id}`} style={{ marginTop: 0 }}>
<div data-cy={`textarea-${id}`} style={{ marginTop: 0 }} ref={editorContainerRef}>
<div
className="form-text-area"
style={{
Expand Down

0 comments on commit 381fa0e

Please sign in to comment.