Skip to content

Commit 34f3709

Browse files
committed
feat: Sets focus to ChatForm's <textarea> after load
Sets the focus to the textarea element when the component mounts and after the loading state changes from true to false. This improves user experience by automatically placing the cursor in the input field, allowing users to start typing immediately.
1 parent 14e8ac8 commit 34f3709

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tools/server/webui/src/lib/components/chat/ChatForm.svelte

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import type { ChatUploadedFile } from '$lib/types/chat.d.ts';
66
import { ChatAttachmentsList } from '$lib/components';
77
import { inputClasses } from '$lib/constants/input-classes';
8+
import { onMount } from 'svelte';
89
910
interface Props {
1011
class?: string;
@@ -35,6 +36,21 @@
3536
let message = $state('');
3637
let textareaElement: HTMLTextAreaElement | undefined;
3738
let fileInputElement: HTMLInputElement | undefined;
39+
let previousIsLoading = $state(isLoading);
40+
41+
onMount(() => {
42+
if (textareaElement) {
43+
textareaElement.focus();
44+
}
45+
});
46+
47+
$effect(() => {
48+
if (previousIsLoading && !isLoading && textareaElement) {
49+
textareaElement.focus();
50+
}
51+
52+
previousIsLoading = isLoading;
53+
});
3854
3955
async function handleSubmit(event: SubmitEvent) {
4056
event.preventDefault();

0 commit comments

Comments
 (0)