diff --git a/app/scenes/Document/components/Comments/CommentForm.tsx b/app/scenes/Document/components/Comments/CommentForm.tsx index 1688aff140..ba571cf002 100644 --- a/app/scenes/Document/components/Comments/CommentForm.tsx +++ b/app/scenes/Document/components/Comments/CommentForm.tsx @@ -103,6 +103,11 @@ function CommentForm({ useOnClickOutside(formRef, reset); + React.useEffect(() => { + window.addEventListener("beforeunload", reset); + return () => window.removeEventListener("beforeunload", reset); + }, [reset]); + const handleCreateComment = action(async (event: React.FormEvent) => { event.preventDefault(); @@ -254,11 +259,13 @@ function CommentForm({ const handleMounted = React.useCallback( (ref) => { if (autoFocus && ref && !hasFocusedOnMount.current) { - ref.focusAtStart(); + if (!draft) { + ref.focusAtStart(); + } hasFocusedOnMount.current = true; } }, - [autoFocus] + [autoFocus, draft] ); const presence = animatePresence