Skip to content

Commit 925922a

Browse files
committed
add auto focus to message input
1 parent 8dd37b2 commit 925922a

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

service/frontend/src/components/MessageInput.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React, { useState, useRef, useEffect } from 'react';
22
import { uploadEmbeddingText, createAccessToken, searchMemories } from '../services/api';
33

44
function MessageInput({ input, setInput, handleSubmit, isLoading, isStreaming, onCancel, onEmbedUpload, chatSessionId, onAuthError }) {
@@ -16,6 +16,20 @@ function MessageInput({ input, setInput, handleSubmit, isLoading, isStreaming, o
1616
const [isTokenLoading, setIsTokenLoading] = useState(false);
1717
const [createdToken, setCreatedToken] = useState('');
1818

19+
// Ref for the message input field
20+
const inputRef = useRef(null);
21+
22+
// Auto-focus the input when component mounts and when loading completes
23+
useEffect(() => {
24+
// Focus the input when not loading and not streaming
25+
if (!isLoading && !isStreaming && inputRef.current && chatSessionId) {
26+
// Small delay to ensure the component is fully rendered
27+
setTimeout(() => {
28+
inputRef.current.focus();
29+
}, 100);
30+
}
31+
}, [isLoading, isStreaming, chatSessionId]);
32+
1933
const handleEmbedSubmit = async (e) => {
2034
e.preventDefault();
2135
if (!embedText.trim()) return;
@@ -100,6 +114,7 @@ function MessageInput({ input, setInput, handleSubmit, isLoading, isStreaming, o
100114
<div className="border-t border-gray-700 p-4">
101115
<form onSubmit={handleSubmit} className="flex gap-2">
102116
<input
117+
ref={inputRef}
103118
type="text"
104119
value={input}
105120
onChange={(e) => setInput(e.target.value)}

0 commit comments

Comments
 (0)