@@ -162,7 +162,7 @@ export class UUITextareaElement extends LabelMixin('input label', LitElement) {
162
162
* @default undefined
163
163
*/
164
164
@property ( { type : Number } )
165
- maxLength : number | undefined = undefined ;
165
+ maxLength = 0 ;
166
166
167
167
/**
168
168
* Enables automatic height adjustment. The height will be confined within the min and max height if defined.
@@ -206,13 +206,26 @@ export class UUITextareaElement extends LabelMixin('input label', LitElement) {
206
206
}
207
207
208
208
private autoUpdateHeight ( ) {
209
+ const host = this . shadowRoot ! . host ! as HTMLElement ;
209
210
const input = this . _textarea ;
210
211
212
+ // Temporarily lock the height of the shadowroot host to prevent
213
+ // the page scroll from moving when changing the textarea height
214
+ const scrollTop = host . scrollTop ;
215
+ const hostHeight = getComputedStyle ( host ) . height ;
216
+ host . style . display = 'block' ;
217
+ host . style . height = hostHeight ;
218
+
211
219
input . style . height = 'auto' ;
212
220
213
221
if ( input . scrollHeight > input . clientHeight ) {
214
222
input . style . height = input . scrollHeight + 'px' ;
215
223
}
224
+
225
+ // Reset host styles and scroll to where we were
226
+ host . style . removeProperty ( 'display' ) ;
227
+ host . style . removeProperty ( 'height' ) ;
228
+ host . scrollTop = scrollTop ;
216
229
}
217
230
218
231
renderMaxLength ( ) {
@@ -227,7 +240,7 @@ export class UUITextareaElement extends LabelMixin('input label', LitElement) {
227
240
return html `
228
241
${ this . hideLabel === false ? this . renderLabel ( ) : '' }
229
242
< textarea
230
- maxlength =${ ifDefined ( this . maxLength ) }
243
+ maxlength =${ ifDefined ( this . maxLength > 0 ? this . maxLength : undefined ) }
231
244
style ="min-height: ${ this . minHeight } ; max-height: ${ this . maxHeight } "
232
245
id="textarea"
233
246
.value=${ this . value }
@@ -238,7 +251,7 @@ export class UUITextareaElement extends LabelMixin('input label', LitElement) {
238
251
@input=${ this . onInput }
239
252
@change=${ this . onChange } >
240
253
</ textarea >
241
- ${ this . maxLength ? this . renderMaxLength ( ) : '' }
254
+ ${ this . maxLength > 0 ? this . renderMaxLength ( ) : '' }
242
255
` ;
243
256
}
244
257
}
0 commit comments