@@ -13,7 +13,9 @@ import { ifDefined } from 'lit/directives/if-defined.js';
13
13
* @cssprop --uui-textarea-min-height - Sets the minimum height of the textarea
14
14
* @cssprop --uui-textarea-max-height - Sets the maximum height of the textarea
15
15
* @cssprop {color} --uui-textarea-background-color - Sets the background color of the textarea
16
+ * @cssprop --uui-textarea-font-size - Overwrites the default font size
16
17
*/
18
+
17
19
@defineElement ( 'uui-textarea' )
18
20
export class UUITextareaElement extends FormControlMixin ( LitElement ) {
19
21
/**
@@ -71,10 +73,10 @@ export class UUITextareaElement extends FormControlMixin(LitElement) {
71
73
box-sizing: border-box;
72
74
min-width: 100%;
73
75
max-width: 100%;
74
- font-size: var(--uui-size-5) ;
76
+ font-size: inherit ;
75
77
padding: var(--uui-size-2);
76
78
border: 1px solid
77
- var(--uui-textarea-border-color, var(--uui-color-border));
79
+ var(--uui-textarea-border-color, var(--uui-color-border)); /** Note: Specified border size is needed and hardcoded in autoUpdateHeight() */
78
80
border-radius: 0;
79
81
outline: none;
80
82
min-height: var(--uui-textarea-min-height);
@@ -262,6 +264,12 @@ export class UUITextareaElement extends FormControlMixin(LitElement) {
262
264
if ( ! this . label ) {
263
265
console . warn ( this . tagName + ' needs a `label`' , this ) ;
264
266
}
267
+
268
+ if ( this . autoHeight ) {
269
+ requestAnimationFrame ( ( ) => {
270
+ this . autoUpdateHeight ( ) ;
271
+ } ) ;
272
+ }
265
273
}
266
274
267
275
/**
@@ -305,8 +313,11 @@ export class UUITextareaElement extends FormControlMixin(LitElement) {
305
313
306
314
input . style . height = 'auto' ;
307
315
308
- if ( input . scrollHeight > input . clientHeight ) {
309
- input . style . height = input . scrollHeight + 'px' ;
316
+ // Note: Add + 2 because of the border top+bottom 1px each
317
+ if ( input . scrollHeight + 2 > input . clientHeight ) {
318
+ input . style . height = input . scrollHeight + 2 + 'px' ;
319
+ } else if ( input . scrollHeight + 2 < input . clientHeight ) {
320
+ input . style . removeProperty ( 'height' ) ;
310
321
}
311
322
312
323
// Reset host styles and scroll to where we were
@@ -319,8 +330,8 @@ export class UUITextareaElement extends FormControlMixin(LitElement) {
319
330
return html `
320
331
< textarea
321
332
id ="textarea "
322
- . rows =${ this . rows }
323
- . cols =${ this . cols }
333
+ rows =${ ifDefined ( this . rows ) }
334
+ cols =${ ifDefined ( this . cols ) }
324
335
.value=${ this . value as string }
325
336
.name=${ this . name }
326
337
wrap=${ ifDefined ( this . wrap ) }
0 commit comments