|
@@ -37,6 +37,7 @@ export interface ChatTextareaApi {
|
|
|
setValue: (value: string) => void;
|
|
setValue: (value: string) => void;
|
|
|
focus: () => void;
|
|
focus: () => void;
|
|
|
ref: React.RefObject<HTMLTextAreaElement>;
|
|
ref: React.RefObject<HTMLTextAreaElement>;
|
|
|
|
|
+ refOnSubmit: React.MutableRefObject<(() => void) | null>; // Submit handler
|
|
|
onInput: (event: React.FormEvent<HTMLTextAreaElement>) => void; // Input handler
|
|
onInput: (event: React.FormEvent<HTMLTextAreaElement>) => void; // Input handler
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -46,6 +47,7 @@ export interface ChatTextareaApi {
|
|
|
export function useChatTextarea(initValue: string): ChatTextareaApi {
|
|
export function useChatTextarea(initValue: string): ChatTextareaApi {
|
|
|
const [savedInitValue, setSavedInitValue] = useState<string>(initValue);
|
|
const [savedInitValue, setSavedInitValue] = useState<string>(initValue);
|
|
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
|
|
|
+ const onSubmitRef = useRef<(() => void) | null>(null);
|
|
|
|
|
|
|
|
// Effect to set initial value and height on mount or when initValue changes
|
|
// Effect to set initial value and height on mount or when initValue changes
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
@@ -91,6 +93,7 @@ export function useChatTextarea(initValue: string): ChatTextareaApi {
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
ref: textareaRef,
|
|
ref: textareaRef,
|
|
|
|
|
+ refOnSubmit: onSubmitRef,
|
|
|
onInput: handleInput,
|
|
onInput: handleInput,
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|