diff --git a/src/components/EmojiButton.tsx b/src/components/EmojiButton.tsx index 834e023..d484122 100644 --- a/src/components/EmojiButton.tsx +++ b/src/components/EmojiButton.tsx @@ -18,9 +18,15 @@ const EmojiButton: FC = ({ onSelect }) => { const [open, setOpen] = useState(false) const handleSelect = (value: string) => { - onSelect?.(value) setOpen(false) + onSelect?.(value) } + + const handleCloseAutoFocus = (event: Event) => { + // Close does not trigger focus + event.preventDefault() + } + return ( @@ -28,7 +34,7 @@ const EmojiButton: FC = ({ onSelect }) => { - + {emojiGroups.map((group, index) => { return ( diff --git a/src/components/MessageInput.tsx b/src/components/MessageInput.tsx index 71d65cb..4ebb1ad 100644 --- a/src/components/MessageInput.tsx +++ b/src/components/MessageInput.tsx @@ -1,5 +1,6 @@ -import { type FC, type ChangeEvent, type KeyboardEvent } from 'react' +import { type ChangeEvent, type KeyboardEvent } from 'react' +import React from 'react' import { Textarea } from '@/components/ui/Textarea' import { Markdown } from '@/components/ui/Markdown' import { cn } from '@/utils' @@ -9,48 +10,53 @@ export interface MessageInputProps { className?: string maxLength?: number preview?: boolean + autoFocus?: boolean onInput?: (value: string) => void onEnter?: (value: string) => void } -const MessageInput: FC = ({ value = '', className, maxLength = 500, onInput, onEnter, preview }) => { - const handleKeyDown = (e: KeyboardEvent) => { - if (e.key === 'Enter' && !(e.shiftKey || e.ctrlKey || e.altKey || e.metaKey)) { - e.preventDefault() - onEnter?.(value) +const MessageInput = React.forwardRef( + ({ value = '', className, maxLength = 500, onInput, onEnter, preview, autoFocus }, ref) => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Enter' && !(e.shiftKey || e.ctrlKey || e.altKey || e.metaKey)) { + e.preventDefault() + onEnter?.(value) + } + } + const handleInput = (e: ChangeEvent) => { + onInput?.(e.target.value) } - } - const handleInput = (e: ChangeEvent) => { - onInput?.(e.target.value) - } - return ( -
- {preview ? ( - {value} - ) : ( - // Hack: Auto-Growing Textarea -
-