@@ -4,6 +4,7 @@ import clsx from 'clsx';
4
4
5
5
import type {
6
6
ButtonProps ,
7
+ CharacterLimitPropType ,
7
8
FocusableElement ,
8
9
HideMsgPropType ,
9
10
IconsHorizontalPropType ,
@@ -75,6 +76,7 @@ export class KolInputEmail implements InputEmailAPI, FocusableElement {
75
76
private readonly onInput = ( event : InputEvent ) => {
76
77
const value = ( event . target as HTMLInputElement ) . value ;
77
78
setState ( this , '_currentLength' , value . length ) ;
79
+ this . controller . updateCurrentLengthDebounced ( value . length ) ;
78
80
this . _value = value ;
79
81
this . controller . onFacade . onInput ( event ) ;
80
82
} ;
@@ -92,10 +94,13 @@ export class KolInputEmail implements InputEmailAPI, FocusableElement {
92
94
}
93
95
94
96
private getInputProps ( ) : InputStateWrapperProps {
97
+ const ariaDescribedBy = this . controller . hasCharacterLimit ( ) ? [ `${ this . state . _id } -character-limit-hint` ] : undefined ; // When a character limit is defined, we provide an additional hint referenced by aria-describedby.
98
+
95
99
return {
96
100
ref : this . catchRef ,
97
101
state : this . state ,
98
102
type : 'email' ,
103
+ ariaDescribedBy,
99
104
...this . controller . onFacade ,
100
105
onInput : this . onInput ,
101
106
onKeyDown : this . onKeyDown ,
@@ -133,16 +138,15 @@ export class KolInputEmail implements InputEmailAPI, FocusableElement {
133
138
@Prop ( ) public _autoComplete ?: InputTypeOnOff ;
134
139
135
140
/**
136
- * Makes the element not focusable and ignore all events.
137
- * @TODO : Change type back to `DisabledPropType` after Stencil#4663 has been resolved.
141
+ * When defined, a remaining characters counter is shown. The field is marked as invalid when the character limit has been exceeded.
138
142
*/
139
- @Prop ( ) public _disabled ?: boolean = false ;
143
+ @Prop ( ) public _characterLimit ?: CharacterLimitPropType ;
140
144
141
145
/**
142
- * Shows the character count on the lower border of the input .
143
- * @TODO : Change type back to `HasCounterPropType ` after Stencil#4663 has been resolved.
146
+ * Makes the element not focusable and ignore all events .
147
+ * @TODO : Change type back to `DisabledPropType ` after Stencil#4663 has been resolved.
144
148
*/
145
- @Prop ( ) public _hasCounter ?: boolean = false ;
149
+ @Prop ( ) public _disabled ?: boolean = false ;
146
150
147
151
/**
148
152
* Hides the error message but leaves it in the DOM for the input's aria-describedby.
@@ -264,6 +268,7 @@ export class KolInputEmail implements InputEmailAPI, FocusableElement {
264
268
@State ( ) public state : InputEmailStates = {
265
269
_autoComplete : 'off' ,
266
270
_currentLength : 0 ,
271
+ _currentLengthDebounced : 0 ,
267
272
_hasValue : false ,
268
273
_hideMsg : false ,
269
274
_id : `id-${ nonce ( ) } ` ,
@@ -291,16 +296,16 @@ export class KolInputEmail implements InputEmailAPI, FocusableElement {
291
296
this . controller . validateAutoComplete ( value ) ;
292
297
}
293
298
299
+ @Watch ( '_characterLimit' )
300
+ public validateCharacterLimit ( value ?: CharacterLimitPropType ) : void {
301
+ this . controller . validateCharacterLimit ( value ) ;
302
+ }
303
+
294
304
@Watch ( '_disabled' )
295
305
public validateDisabled ( value ?: boolean ) : void {
296
306
this . controller . validateDisabled ( value ) ;
297
307
}
298
308
299
- @Watch ( '_hasCounter' )
300
- public validateHasCounter ( value ?: boolean ) : void {
301
- this . controller . validateHasCounter ( value ) ;
302
- }
303
-
304
309
@Watch ( '_hideMsg' )
305
310
public validateHideMsg ( value ?: HideMsgPropType ) : void {
306
311
this . controller . validateHideMsg ( value ) ;
0 commit comments