@@ -131,8 +131,6 @@ interface ChatInputSetInputOptions {
131
131
}
132
132
133
133
class ChatInput extends LightElement {
134
- private _disabled = false ;
135
-
136
134
@property ( ) placeholder = "Enter a message..." ;
137
135
// disabled is reflected manually because `reflect: true` doesn't work with LightElement
138
136
@property ( { type : Boolean } )
@@ -155,6 +153,27 @@ class ChatInput extends LightElement {
155
153
this . #onInput( ) ;
156
154
}
157
155
156
+ private _disabled = false ;
157
+ inputVisibleObserver ?: IntersectionObserver ;
158
+
159
+ connectedCallback ( ) : void {
160
+ super . connectedCallback ( ) ;
161
+
162
+ this . inputVisibleObserver = new IntersectionObserver ( ( entries ) => {
163
+ entries . forEach ( ( entry ) => {
164
+ if ( entry . isIntersecting ) this . #updateHeight( ) ;
165
+ } ) ;
166
+ } ) ;
167
+
168
+ this . inputVisibleObserver . observe ( this ) ;
169
+ }
170
+
171
+ disconnectedCallback ( ) : void {
172
+ super . disconnectedCallback ( ) ;
173
+ this . inputVisibleObserver ?. disconnect ( ) ;
174
+ this . inputVisibleObserver = undefined ;
175
+ }
176
+
158
177
attributeChangedCallback (
159
178
name : string ,
160
179
_old : string | null ,
@@ -189,7 +208,7 @@ class ChatInput extends LightElement {
189
208
return html `
190
209
< textarea
191
210
id ="${ this . id } "
192
- class ="form-control textarea-autoresize "
211
+ class ="form-control "
193
212
rows ="1 "
194
213
placeholder ="${ this . placeholder } "
195
214
@keydown =${ this . #onKeyDown}
@@ -217,6 +236,7 @@ class ChatInput extends LightElement {
217
236
}
218
237
219
238
#onInput( ) : void {
239
+ this . #updateHeight( ) ;
220
240
this . button . disabled = this . disabled
221
241
? true
222
242
: this . value . trim ( ) . length === 0 ;
@@ -247,6 +267,15 @@ class ChatInput extends LightElement {
247
267
if ( focus ) this . textarea . focus ( ) ;
248
268
}
249
269
270
+ #updateHeight( ) : void {
271
+ const el = this . textarea ;
272
+ if ( el . scrollHeight == 0 ) {
273
+ return ;
274
+ }
275
+ el . style . height = "auto" ;
276
+ el . style . height = `${ el . scrollHeight } px` ;
277
+ }
278
+
250
279
setInputValue (
251
280
value : string ,
252
281
{ submit = false , focus = false } : ChatInputSetInputOptions = { }
0 commit comments