feat: Enhance form submission for touch screens

This commit is contained in:
Marco Beretta 2025-05-02 23:22:26 +02:00 committed by Danny Avila
parent 6e663b2480
commit 4eb0d3b073
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956

View file

@ -126,6 +126,16 @@ const ChatForm = memo(({ index = 0 }: { index?: number }) => {
});
const { submitMessage, submitPrompt } = useSubmitMessage();
const isTouchScreen = useMemo(() => window.matchMedia?.('(pointer: coarse)').matches, []);
const onSubmit = methods.handleSubmit((data: { text: string }) => {
submitMessage(data);
if (isTouchScreen) {
textAreaRef.current?.blur();
}
});
const handleKeyUp = useHandleKeyUp({
index,
textAreaRef,
@ -199,7 +209,7 @@ const ChatForm = memo(({ index = 0 }: { index?: number }) => {
return (
<form
onSubmit={methods.handleSubmit(submitMessage)}
onSubmit={onSubmit}
className={cn(
'mx-auto flex flex-row gap-3 sm:px-2',
maximizeChatSpace ? 'w-full max-w-full' : 'md:max-w-3xl xl:max-w-4xl',