@@ -17,12 +17,8 @@ export class UUITextareaElement extends LabelMixin(
17
17
) {
18
18
static styles = [
19
19
css `
20
- :host {
21
- display: flex;
22
- flex-direction: column;
23
- }
24
20
:host([disabled]) .label,
25
- :host([disabled]) #char-count {
21
+ :host([disabled]) #max-length-counter {
26
22
color: var(--uui-interface-contrast-disabled);
27
23
}
28
24
:host([error]) textarea {
@@ -34,6 +30,11 @@ export class UUITextareaElement extends LabelMixin(
34
30
:host([auto-height]) textarea {
35
31
resize: none;
36
32
}
33
+ .label {
34
+ display: inline-block;
35
+ margin-bottom: var(--uui-size-1);
36
+ font-weight: bold;
37
+ }
37
38
textarea[disabled] {
38
39
cursor: not-allowed;
39
40
background-color: var(
@@ -48,19 +49,30 @@ export class UUITextareaElement extends LabelMixin(
48
49
49
50
color: var(--uui-interface-contrast-disabled);
50
51
}
51
-
52
- #textarea {
52
+ textarea {
53
+ font-family: inherit;
54
+ box-sizing: border-box;
53
55
min-width: 100%;
54
56
max-width: 100%;
57
+ font-size: var(--uui-size-5);
58
+ padding: var(--uui-size-2);
55
59
border: 1px solid
56
60
var(--uui-textarea-border-color, var(--uui-interface-border));
57
61
border-radius: 0;
62
+ outline: none;
58
63
}
59
- #char-count {
64
+ #lengths-container {
65
+ display: flex;
66
+ }
67
+ #min-length-counter {
68
+ color: var(--uui-look-danger-surface);
69
+ margin-right: 1em;
70
+ }
71
+ #max-length-counter {
60
72
display: inline-block;
61
73
width: min-content;
62
74
}
63
- #char-count .maxed {
75
+ #max-length-counter .maxed {
64
76
animation-name: maxed;
65
77
animation-duration: 0.1s;
66
78
animation-direction: alternate;
@@ -163,6 +175,15 @@ export class UUITextareaElement extends LabelMixin(
163
175
@query ( '#textarea' )
164
176
protected _textarea ! : HTMLInputElement ;
165
177
178
+ /**
179
+ * Defines the min length of the textarea.
180
+ * @type {number }
181
+ * @attr
182
+ * @default undefined
183
+ */
184
+ @property ( { type : Number } )
185
+ minLength = 0 ;
186
+
166
187
/**
167
188
* Defines the max length of the textarea.
168
189
* @type {number }
@@ -201,6 +222,9 @@ export class UUITextareaElement extends LabelMixin(
201
222
202
223
private onInput ( e : Event ) {
203
224
this . value = ( e . target as HTMLInputElement ) . value ;
225
+ this . dispatchEvent (
226
+ new UUITextareaEvent ( UUITextareaEvent . INPUT , { bubbles : true } )
227
+ ) ;
204
228
205
229
if ( this . autoHeight ) {
206
230
this . autoUpdateHeight ( ) ;
@@ -238,17 +262,26 @@ export class UUITextareaElement extends LabelMixin(
238
262
239
263
renderMaxLength ( ) {
240
264
return html `< span
241
- id ="char-count "
265
+ id ="max-length-counter "
242
266
class =${ this . value . length >= this . maxLength ! ? 'maxed' : '' }
243
267
> ${ this . value ? this . value . length : 0 } /${ this . maxLength } </ span
244
268
> ` ;
245
269
}
270
+ renderMinLength ( ) {
271
+ const shouldRender = this . minLength - this . value . length > 0 ;
272
+ return shouldRender
273
+ ? html `< span id ="min-length-counter ">
274
+ ${ this . minLength - this . value . length }
275
+ </ span > `
276
+ : '' ;
277
+ }
246
278
247
279
render ( ) {
248
280
return html `
249
281
${ this . hideLabel === false ? this . renderLabel ( ) : '' }
250
282
< textarea
251
283
maxlength =${ ifDefined ( this . maxLength > 0 ? this . maxLength : undefined ) }
284
+ minlength =${ this . minLength }
252
285
style="min-height: ${ this . minHeight } ; max-height: ${ this . maxHeight } "
253
286
id="textarea"
254
287
.value=${ this . value }
@@ -259,7 +292,10 @@ export class UUITextareaElement extends LabelMixin(
259
292
@input=${ this . onInput }
260
293
@change=${ this . onChange } >
261
294
</ textarea >
262
- ${ this . maxLength > 0 ? this . renderMaxLength ( ) : '' }
295
+ < div id ="lengths-container ">
296
+ ${ this . minLength > 0 ? this . renderMinLength ( ) : '' }
297
+ ${ this . maxLength > 0 ? this . renderMaxLength ( ) : '' }
298
+ </ div >
263
299
` ;
264
300
}
265
301
}
0 commit comments