Skip to content

Commit 41add52

Browse files
committed
fix: textarea focus
1 parent 852c48b commit 41add52

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

frontend/src/components/ui/input-group.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function InputGroupTextarea({ className, ...props }: React.ComponentProps<'texta
134134
);
135135
}
136136

137-
function InputGroupTextareaAutosize({ className, ...props }: React.ComponentPropsWithoutRef<typeof TextareaAutosize>) {
137+
function InputGroupTextareaAutosize({ className, ...props }: React.ComponentProps<typeof TextareaAutosize>) {
138138
return (
139139
<TextareaAutosize
140140
className={cn(

frontend/src/features/flows/flow-form.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { zodResolver } from '@hookform/resolvers/zod';
22
import { ArrowUpIcon, Check, ChevronDown, Square, X } from 'lucide-react';
3-
import { useEffect, useMemo, useState } from 'react';
3+
import { useEffect, useMemo, useRef, useState } from 'react';
44
import { useForm } from 'react-hook-form';
55
import { z } from 'zod';
66

@@ -123,6 +123,18 @@ export const FlowForm = ({
123123

124124
const isFormDisabled = isDisabled || isLoading || isSubmitting || isCanceling;
125125

126+
const textareaRef = useRef<HTMLTextAreaElement>(null);
127+
const previousFormDisabledRef = useRef(isFormDisabled);
128+
129+
useEffect(() => {
130+
const isDisabled = previousFormDisabledRef.current;
131+
previousFormDisabledRef.current = isFormDisabled;
132+
133+
if (isDisabled && !isFormDisabled) {
134+
textareaRef.current?.focus();
135+
}
136+
}, [isFormDisabled]);
137+
126138
const handleSubmit = async (values: FlowFormValues) => {
127139
await onSubmit(values);
128140
resetField('message');
@@ -157,6 +169,10 @@ export const FlowForm = ({
157169
minRows={1}
158170
onKeyDown={handleKeyDown}
159171
placeholder={placeholder}
172+
ref={(element) => {
173+
field.ref(element);
174+
textareaRef.current = element;
175+
}}
160176
/>
161177
<InputGroupAddon align="block-end">
162178
<FormField

0 commit comments

Comments
 (0)