@@ -14,7 +14,7 @@ const EditView = ({
14
14
content,
15
15
setIsEdit,
16
16
messageIndex,
17
- sticky,
17
+ sticky
18
18
} : {
19
19
content : string ;
20
20
setIsEdit : React . Dispatch < React . SetStateAction < boolean > > ;
@@ -28,6 +28,7 @@ const EditView = ({
28
28
const [ _content , _setContent ] = useState < string > ( content ) ;
29
29
const [ isModalOpen , setIsModalOpen ] = useState < boolean > ( false ) ;
30
30
const textareaRef = React . createRef < HTMLTextAreaElement > ( ) ;
31
+ const bufferRef = React . createRef < HTMLTextAreaElement > ( ) ;
31
32
32
33
const { t } = useTranslation ( ) ;
33
34
@@ -105,18 +106,23 @@ const EditView = ({
105
106
handleSubmit ( ) ;
106
107
} ;
107
108
108
- useEffect ( ( ) => {
109
- if ( textareaRef . current ) {
110
- textareaRef . current . style . height = 'auto' ;
111
- textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
109
+ const adjustTextareaHeight = ( ) => {
110
+ if ( textareaRef . current && bufferRef . current ) {
111
+ const textarea = textareaRef . current ;
112
+ const buffer = bufferRef . current ;
113
+
114
+ buffer . style . height = 'auto' ;
115
+ buffer . style . height = buffer . scrollHeight + 'px' ;
116
+ textarea . style . height = buffer . scrollHeight + 'px' ;
112
117
}
118
+ } ;
119
+
120
+ useEffect ( ( ) => {
121
+ adjustTextareaHeight ( ) ;
113
122
} , [ _content ] ) ;
114
123
115
124
useEffect ( ( ) => {
116
- if ( textareaRef . current ) {
117
- textareaRef . current . style . height = 'auto' ;
118
- textareaRef . current . style . height = `${ textareaRef . current . scrollHeight } px` ;
119
- }
125
+ adjustTextareaHeight ( ) ;
120
126
} , [ ] ) ;
121
127
122
128
return (
@@ -128,6 +134,7 @@ const EditView = ({
128
134
: ''
129
135
} `}
130
136
>
137
+ < div className = "relative" >
131
138
< textarea
132
139
ref = { textareaRef }
133
140
className = 'm-0 resize-none rounded-lg bg-transparent overflow-y-hidden focus:ring-0 focus-visible:ring-0 leading-7 w-full placeholder:text-gray-500/40'
@@ -139,6 +146,19 @@ const EditView = ({
139
146
onKeyDown = { handleKeyDown }
140
147
rows = { 1 }
141
148
> </ textarea >
149
+ < textarea
150
+ ref = { bufferRef }
151
+ className = 'm-0 resize-none rounded-lg bg-transparent overflow-y-hidden focus:ring-0 focus-visible:ring-0 leading-7 w-full placeholder:text-gray-500/40 absolute top-0 left-0'
152
+ style = { {
153
+ position : 'absolute' ,
154
+ visibility : 'hidden' ,
155
+ overflow : 'hidden'
156
+ } }
157
+ value = { _content }
158
+ readOnly
159
+ rows = { 1 }
160
+ > </ textarea >
161
+ </ div >
142
162
</ div >
143
163
< EditViewButtons
144
164
sticky = { sticky }
0 commit comments