diff --git a/components/email/ComposeEmail.tsx b/components/email/ComposeEmail.tsx index adb9b1d6..c89e353b 100644 --- a/components/email/ComposeEmail.tsx +++ b/components/email/ComposeEmail.tsx @@ -186,9 +186,15 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { setEmailContent(content); } - // Focus editor after initializing + // Focus editor after initializing content setTimeout(() => { - if (editorRef.current) { + // For new messages, focus the textarea + if (!type || type === 'new') { + const textarea = document.querySelector('textarea'); + textarea?.focus(); + } + // For replies/forwards, focus the contentEditable div + else if (['reply', 'reply-all', 'forward'].includes(type) && editorRef.current) { editorRef.current.focus(); try { @@ -288,6 +294,11 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { }, 0); }; + // Add a handler for textarea changes + const handleTextareaChange = (e: React.ChangeEvent) => { + setEmailContent(e.target.value); + }; + // Send email const handleSend = async () => { if (!to) { @@ -298,12 +309,18 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { try { setSending(true); + // For new emails, emailContent is already set via onChange + // For replies/forwards, we need to get content from editorRef + const finalContent = type === 'new' + ? emailContent + : editorRef.current?.innerHTML || emailContent; + await onSend({ to, cc: cc || undefined, bcc: bcc || undefined, subject, - body: emailContent, + body: finalContent, attachments }); @@ -411,21 +428,39 @@ export default function ComposeEmail(props: ComposeEmailAllProps) { - {/* Email Body Editor - using same approach as Input components */} + {/* Email Body Editor - different approach based on type */}
-
-