Skip to content

Commit 24cc5b6

Browse files
authored
feat: autofocus message box on user's turn (#143)
1 parent f71b1c0 commit 24cc5b6

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

chat/src/components/message-input.tsx

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ export default function MessageInput({
112112
return () => clearInterval(interval);
113113
}, [sentChars]);
114114

115+
// Autofocus on the message input box on user's turn
116+
useEffect(() => {
117+
if (
118+
serverStatus === "stable" &&
119+
!disabled &&
120+
inputMode === "text" &&
121+
textareaRef.current
122+
) {
123+
textareaRef.current.focus();
124+
}
125+
}, [serverStatus, disabled, inputMode]);
126+
115127
const addSentChar = (char: string) => {
116128
const newChar: SentChar = {
117129
char,
@@ -332,20 +344,20 @@ export default function MessageInput({
332344
);
333345
}
334346

335-
function Char({ char }: { char: string }) {
347+
function Char({char}: { char: string }) {
336348
switch (char) {
337349
case "ArrowUp":
338-
return <ArrowUpIcon className="h-4 w-4" />;
350+
return <ArrowUpIcon className="h-4 w-4"/>;
339351
case "ArrowDown":
340-
return <ArrowDownIcon className="h-4 w-4" />;
352+
return <ArrowDownIcon className="h-4 w-4"/>;
341353
case "ArrowRight":
342-
return <ArrowRightIcon className="h-4 w-4" />;
354+
return <ArrowRightIcon className="h-4 w-4"/>;
343355
case "ArrowLeft":
344-
return <ArrowLeftIcon className="h-4 w-4" />;
356+
return <ArrowLeftIcon className="h-4 w-4"/>;
345357
case "⏎":
346-
return <CornerDownLeftIcon className="h-4 w-4" />;
358+
return <CornerDownLeftIcon className="h-4 w-4"/>;
347359
case "Backspace":
348-
return <DeleteIcon className="h-4 w-4" />;
360+
return <DeleteIcon className="h-4 w-4"/>;
349361
default:
350362
return char;
351363
}

0 commit comments

Comments
 (0)