fix: send button auto height

This commit is contained in:
2024-01-16 17:55:46 +08:00
parent 0eabcc0d0a
commit a4d3091e06
3 changed files with 14 additions and 10 deletions

View File

@@ -392,6 +392,7 @@ export default function ChatBOX(props: {
); );
_setToolsTemplates(templateTools); _setToolsTemplates(templateTools);
}; };
const userInputRef = createRef();
return ( return (
<div className="grow flex flex-col p-2 dark:text-black"> <div className="grow flex flex-col p-2 dark:text-black">
@@ -812,9 +813,10 @@ export default function ChatBOX(props: {
)} )}
<textarea <textarea
value={inputMsg} value={inputMsg}
ref={userInputRef}
onChange={(event: any) => { onChange={(event: any) => {
setInputMsg(event.target.value); setInputMsg(event.target.value);
autoHeight(event); autoHeight(event.target);
}} }}
onKeyPress={(event: any) => { onKeyPress={(event: any) => {
console.log(event); console.log(event);
@@ -822,10 +824,10 @@ export default function ChatBOX(props: {
send(event.target.value, true); send(event.target.value, true);
setInputMsg(""); setInputMsg("");
event.target.value = ""; event.target.value = "";
autoHeight(event); autoHeight(event.target);
return; return;
} }
autoHeight(event); autoHeight(event.target);
setInputMsg(event.target.value); setInputMsg(event.target.value);
}} }}
className="rounded grow m-1 p-1 border-2 border-gray-400 w-0" className="rounded grow m-1 p-1 border-2 border-gray-400 w-0"
@@ -836,6 +838,8 @@ export default function ChatBOX(props: {
disabled={showGenerating} disabled={showGenerating}
onClick={() => { onClick={() => {
send(inputMsg, true); send(inputMsg, true);
userInputRef.current.value = "";
autoHeight(userInputRef.current);
}} }}
> >
{Tr("Send")} {Tr("Send")}

View File

@@ -81,10 +81,10 @@ const LongInput = (props: {
onChange={(event: any) => { onChange={(event: any) => {
props.chatStore[props.field] = event.target.value; props.chatStore[props.field] = event.target.value;
props.setChatStore({ ...props.chatStore }); props.setChatStore({ ...props.chatStore });
autoHeight(event); autoHeight(event.target);
}} }}
onKeyPress={(event: any) => { onKeyPress={(event: any) => {
autoHeight(event); autoHeight(event.target);
}} }}
></textarea> ></textarea>
</Help> </Help>

View File

@@ -1,9 +1,9 @@
export const autoHeight = (event: any) => { export const autoHeight = (target: any) => {
event.target.style.height = "auto"; target.style.height = "auto";
// max 70% of screen height // max 70% of screen height
event.target.style.height = `${Math.min( target.style.height = `${Math.min(
event.target.scrollHeight, target.scrollHeight,
window.innerHeight * 0.7 window.innerHeight * 0.7
)}px`; )}px`;
console.log("set auto height", event.target.style.height); console.log("set auto height", target.style.height);
}; };