Skip to content

Commit

Permalink
feat(MessageInput): add composition event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
minai621 committed Oct 30, 2024
1 parent b33e5fe commit a169418
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion ui/components/MessageInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MessageInput = ({
const [message, setMessage] = useState('');
const [textareaRows, setTextareaRows] = useState(1);
const [mode, setMode] = useState<'multi' | 'single'>('single');
const [isComposing, setIsComposing] = useState(false);

useEffect(() => {
if (textareaRows >= 2 && message && mode === 'single') {
Expand Down Expand Up @@ -58,7 +59,7 @@ const MessageInput = ({
setMessage('');
}}
onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey && !loading) {
if (e.key === 'Enter' && !e.shiftKey && !loading && !isComposing) {
e.preventDefault();
sendMessage(message);
setMessage('');
Expand All @@ -74,6 +75,8 @@ const MessageInput = ({
ref={inputRef}
value={message}
onChange={(e) => setMessage(e.target.value)}
onCompositionStart={() => setIsComposing(true)}
onCompositionEnd={() => setIsComposing(false)}
onHeightChange={(height, props) => {
setTextareaRows(Math.ceil(height / props.rowHeight));
}}
Expand Down

0 comments on commit a169418

Please sign in to comment.