packages/components/directives/eui-maxlength.directive.ts
A directive that adds maxLength functionality to input and textarea elements with visual feedback. It shows the remaining characters count and provides visual indication when the limit is reached.
Example :### Basic usage
```html
<input [euiMaxlength]="50"><input [formControlName]="'name'" [euiMaxlength]="100"><textarea [euiMaxlength]="200" [isShowMaxlength]="false"></textarea>
AfterContentInit
OnDestroy
OnChanges
| Selector |
input[euiMaxlength],
textarea[euiMaxlength],
[ngModel][euiMaxlength],
[formControlName][euiMaxlength] |
Properties |
Methods |
Inputs |
Outputs |
HostListeners |
constructor()
|
| euiMaxlength |
Type : number
|
|
It accepts number values to indicate the maxLength of an input. To reset or disable it set the value to null. NULL value will remove any MaxLength indicator even if another input like isShowMaxlength equals true. |
| isShowMaxlength |
Type : boolean
|
Default value : true
|
|
Controls the visibility of the maxLength indicator. When true, shows a counter with remaining characters. When false, hides the counter but maintains the maxLength restriction. |
| maxLengthReached |
Type : EventEmitter<boolean>
|
|
Emits when the input value length reaches or exceeds the maxLength limit. Emits true when a limit is reached, false when below limit. |
| change |
| input |
| paste |
Arguments : '$any($event)'
|
| onChange |
onChange()
|
Decorators :
@HostListener('change')
|
|
Returns :
void
|
| onInput |
onInput()
|
Decorators :
@HostListener('input')
|
|
Returns :
void
|
| onPaste | ||||||
onPaste(event: ClipboardEvent)
|
||||||
Decorators :
@HostListener('paste', ['$any($event)'])
|
||||||
|
Parameters :
Returns :
void
|
| Public setLengthCalcFactory | ||||||||
setLengthCalcFactory(fn: (input: string) => void)
|
||||||||
|
Sets a custom function to calculate the length of the input value. Useful for implementing custom length calculation logic (e.g., counting characters differently). Example :
Parameters :
Returns :
void
|
| valueChangesSubscription |
Type : Subscription
|