Skip to content

Commit dbacc94

Browse files
committed
resizing the inputbox on submit
1 parent ad71a77 commit dbacc94

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

frontend/nextjs/app/globals.css

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ html {
1313
}
1414

1515
textarea {
16-
transition: height 0.2s ease-in-out;
16+
max-height: 300px; /* Set an appropriate max height */
17+
overflow-y: auto; /* Enable internal scrolling */
18+
/* transition: height 0.2s ease-in-out; */
1719
}
1820

1921
.log-message {

frontend/nextjs/components/InputArea.tsx

+25-24
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Image from "next/image";
2-
import { FC } from "react";
2+
import { FC, useRef } from "react";
33
import TypeAnimation from "./TypeAnimation";
4-
import { useRef } from "react";
54

65
type TInputAreaProps = {
76
promptValue: string;
@@ -15,33 +14,34 @@ type TInputAreaProps = {
1514
const InputArea: FC<TInputAreaProps> = ({
1615
promptValue,
1716
setPromptValue,
18-
handleSubmit: handleSubmit,
19-
handleSecondary: handleSecondary,
17+
handleSubmit,
18+
handleSecondary,
2019
disabled,
2120
reset,
2221
}) => {
23-
const placeholder = handleSecondary ? "Follow up questions..." : "What would you like to research next?"
22+
const placeholder = handleSecondary
23+
? "Follow up questions..."
24+
: "What would you like to research next?";
2425

2526
const textareaRef = useRef<HTMLTextAreaElement>(null);
2627

2728
const resetHeight = () => {
2829
if (textareaRef.current) {
29-
textareaRef.current.style.setProperty('height', '3em', 'important');
30+
textareaRef.current.style.height = '3em'; // Reset to base height
3031
}
3132
};
32-
33+
3334
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
3435
if (e.key === 'Enter') {
3536
if (e.shiftKey) {
36-
// Allow new line on Shift+Enter
37-
return;
37+
return; // Allow new line on Shift+Enter
3838
} else {
39-
// Submit form on Enter
4039
e.preventDefault();
4140
if (!disabled) {
4241
if (reset) reset();
4342
handleSubmit(promptValue);
44-
resetHeight()
43+
setPromptValue(''); // Clear prompt value
44+
resetHeight(); // Reset height after submit
4545
}
4646
}
4747
}
@@ -54,24 +54,24 @@ const InputArea: FC<TInputAreaProps> = ({
5454
e.preventDefault();
5555
if (reset) reset();
5656
handleSubmit(promptValue);
57+
setPromptValue(''); // Clear prompt value
5758
resetHeight();
5859
}}
5960
>
60-
{
61-
handleSecondary &&
61+
{handleSecondary && (
6262
<div
63-
role="button"
63+
role="button"
6464
aria-disabled={disabled}
6565
className="relative flex h-[50px] w-[50px] shrink-0 items-center justify-center rounded-[3px] bg-[linear-gradient(154deg,#1B1B16_23.37%,#565646_91.91%)] disabled:pointer-events-none disabled:opacity-75"
66-
onClick={(e) =>{
67-
if (!disabled){
66+
onClick={(e) => {
67+
if (!disabled) {
6868
e.preventDefault();
6969
if (reset) reset();
7070
handleSecondary(promptValue);
71-
resetHeight()
72-
}
71+
setPromptValue(''); // Clear prompt value
72+
resetHeight();
7373
}
74-
}
74+
}}
7575
>
7676
{disabled && (
7777
<div className="absolute inset-0 flex items-center justify-center">
@@ -88,11 +88,12 @@ const InputArea: FC<TInputAreaProps> = ({
8888
className={disabled ? "invisible" : ""}
8989
/>
9090
</div>
91-
}
91+
)}
9292

9393
<textarea
9494
placeholder={placeholder}
95-
className="h-auto focus-visible::outline-0 my-1 w-full pl-5 font-light not-italic leading-[normal]
95+
ref={textareaRef}
96+
className="focus-visible::outline-0 my-1 w-full pl-5 font-light not-italic leading-[normal]
9697
text-[#1B1B16]/30 text-black outline-none focus-visible:ring-0 focus-visible:ring-offset-0
9798
sm:text-xl min-h-[3em] resize-none overflow-hidden"
9899
disabled={disabled}
@@ -101,8 +102,8 @@ const InputArea: FC<TInputAreaProps> = ({
101102
rows={2}
102103
onKeyDown={handleKeyDown}
103104
onChange={(e) => {
104-
// Auto-adjust height
105-
e.target.style.height = `${e.target.scrollHeight}px`;
105+
// e.target.style.height = 'auto'; // Reset height to auto to allow shrinking
106+
e.target.style.height = `${e.target.scrollHeight}px`; // Adjust height
106107
setPromptValue(e.target.value);
107108
}}
108109
/>
@@ -130,4 +131,4 @@ const InputArea: FC<TInputAreaProps> = ({
130131
);
131132
};
132133

133-
export default InputArea;
134+
export default InputArea;

0 commit comments

Comments
 (0)