1
1
import Image from "next/image" ;
2
- import { FC } from "react" ;
2
+ import { FC , useRef } from "react" ;
3
3
import TypeAnimation from "./TypeAnimation" ;
4
- import { useRef } from "react" ;
5
4
6
5
type TInputAreaProps = {
7
6
promptValue : string ;
@@ -15,33 +14,34 @@ type TInputAreaProps = {
15
14
const InputArea : FC < TInputAreaProps > = ( {
16
15
promptValue,
17
16
setPromptValue,
18
- handleSubmit : handleSubmit ,
19
- handleSecondary : handleSecondary ,
17
+ handleSubmit,
18
+ handleSecondary,
20
19
disabled,
21
20
reset,
22
21
} ) => {
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?" ;
24
25
25
26
const textareaRef = useRef < HTMLTextAreaElement > ( null ) ;
26
27
27
28
const resetHeight = ( ) => {
28
29
if ( textareaRef . current ) {
29
- textareaRef . current . style . setProperty ( ' height' , '3em' , 'important' ) ;
30
+ textareaRef . current . style . height = '3em' ; // Reset to base height
30
31
}
31
32
} ;
32
-
33
+
33
34
const handleKeyDown = ( e : React . KeyboardEvent < HTMLTextAreaElement > ) => {
34
35
if ( e . key === 'Enter' ) {
35
36
if ( e . shiftKey ) {
36
- // Allow new line on Shift+Enter
37
- return ;
37
+ return ; // Allow new line on Shift+Enter
38
38
} else {
39
- // Submit form on Enter
40
39
e . preventDefault ( ) ;
41
40
if ( ! disabled ) {
42
41
if ( reset ) reset ( ) ;
43
42
handleSubmit ( promptValue ) ;
44
- resetHeight ( )
43
+ setPromptValue ( '' ) ; // Clear prompt value
44
+ resetHeight ( ) ; // Reset height after submit
45
45
}
46
46
}
47
47
}
@@ -54,24 +54,24 @@ const InputArea: FC<TInputAreaProps> = ({
54
54
e . preventDefault ( ) ;
55
55
if ( reset ) reset ( ) ;
56
56
handleSubmit ( promptValue ) ;
57
+ setPromptValue ( '' ) ; // Clear prompt value
57
58
resetHeight ( ) ;
58
59
} }
59
60
>
60
- {
61
- handleSecondary &&
61
+ { handleSecondary && (
62
62
< div
63
- role = "button"
63
+ role = "button"
64
64
aria-disabled = { disabled }
65
65
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 ) {
68
68
e . preventDefault ( ) ;
69
69
if ( reset ) reset ( ) ;
70
70
handleSecondary ( promptValue ) ;
71
- resetHeight ( )
72
- }
71
+ setPromptValue ( '' ) ; // Clear prompt value
72
+ resetHeight ( ) ;
73
73
}
74
- }
74
+ } }
75
75
>
76
76
{ disabled && (
77
77
< div className = "absolute inset-0 flex items-center justify-center" >
@@ -88,11 +88,12 @@ const InputArea: FC<TInputAreaProps> = ({
88
88
className = { disabled ? "invisible" : "" }
89
89
/>
90
90
</ div >
91
- }
91
+ ) }
92
92
93
93
< textarea
94
94
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]
96
97
text-[#1B1B16]/30 text-black outline-none focus-visible:ring-0 focus-visible:ring-offset-0
97
98
sm:text-xl min-h-[3em] resize-none overflow-hidden"
98
99
disabled = { disabled }
@@ -101,8 +102,8 @@ const InputArea: FC<TInputAreaProps> = ({
101
102
rows = { 2 }
102
103
onKeyDown = { handleKeyDown }
103
104
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
106
107
setPromptValue ( e . target . value ) ;
107
108
} }
108
109
/>
@@ -130,4 +131,4 @@ const InputArea: FC<TInputAreaProps> = ({
130
131
) ;
131
132
} ;
132
133
133
- export default InputArea ;
134
+ export default InputArea ;
0 commit comments