From 135da9fafacf417be96fa1dbdb933169b45cbb88 Mon Sep 17 00:00:00 2001 From: Andreea <63120475+ezra0619@users.noreply.github.com> Date: Tue, 12 Dec 2023 12:50:48 +0100 Subject: [PATCH] added debounce to klp-form-text-input --- .../demo/src/app/demo/demo.component.html | 4 ++++ projects/demo/src/app/demo/demo.component.ts | 1 + .../klippa/ngx-enhancy-forms/package.json | 2 +- .../text-input/text-input.component.html | 3 ++- .../text-input/text-input.component.ts | 23 +++++++++++++++---- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/projects/demo/src/app/demo/demo.component.html b/projects/demo/src/app/demo/demo.component.html index db3983c..7bcc7ea 100644 --- a/projects/demo/src/app/demo/demo.component.html +++ b/projects/demo/src/app/demo/demo.component.html @@ -27,6 +27,10 @@ + + + + diff --git a/projects/demo/src/app/demo/demo.component.ts b/projects/demo/src/app/demo/demo.component.ts index 6c12a17..3c120ae 100644 --- a/projects/demo/src/app/demo/demo.component.ts +++ b/projects/demo/src/app/demo/demo.component.ts @@ -78,6 +78,7 @@ export class DemoComponent { emails: [''], disabledButRendered: ['disabledButRendered'], unrendered: ['unrendered'], + testing: '', yesno: false, yesno2: false, selector: [null], diff --git a/projects/klippa/ngx-enhancy-forms/package.json b/projects/klippa/ngx-enhancy-forms/package.json index 6aa18f2..98a59bd 100644 --- a/projects/klippa/ngx-enhancy-forms/package.json +++ b/projects/klippa/ngx-enhancy-forms/package.json @@ -1,6 +1,6 @@ { "name": "@klippa/ngx-enhancy-forms", - "version": "14.10.0", + "version": "14.11.1", "publishConfig": { "access": "public" }, diff --git a/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.html b/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.html index ad8aa3e..ebe1532 100644 --- a/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.html +++ b/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.html @@ -1,3 +1,4 @@ +la
@@ -6,7 +7,7 @@ [type]="type" [(ngModel)]="innerValue" [ngClass]="{showErrors: isInErrorState(), hasIcon: icon?.length > 0, hasClearButton: clearable, noBorderLeft: !hasBorderLeft, noBorderRight: !hasBorderRight}" - (input)="setInnerValueAndNotify($event.target.value)" + (input)="onValueChange($event.target.value)" [placeholder]="placeholder ? placeholder : ''" (blur)="touch(); onBlur.emit()" [disabled]='disabled' diff --git a/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.ts b/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.ts index 2064cb6..dd07ae5 100644 --- a/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.ts +++ b/projects/klippa/ngx-enhancy-forms/src/lib/elements/text-input/text-input.component.ts @@ -1,5 +1,7 @@ import {Component, EventEmitter, Input, Output} from '@angular/core'; import {NG_VALUE_ACCESSOR} from '@angular/forms'; +import {Subject} from "rxjs"; +import {debounceTime} from "rxjs/operators"; import {ValueAccessorBase} from '../value-accessor-base/value-accessor-base.component'; @Component({ @@ -11,9 +13,22 @@ import {ValueAccessorBase} from '../value-accessor-base/value-accessor-base.comp export class TextInputComponent extends ValueAccessorBase { @Input() placeholder: string; @Input() type: 'text' | 'password' = 'text'; - @Input() clearable = false; + @Input() clearable: boolean = false; @Input() icon: 'search'; - @Input() hasBorderLeft = true; - @Input() hasBorderRight = true; - @Output() onBlur = new EventEmitter(); + @Input() hasBorderLeft: boolean = true; + @Input() hasBorderRight: boolean = true; + @Input() debounceMs: number = 0; + @Output() onBlur: EventEmitter = new EventEmitter(); + private valueSubject: Subject = new Subject(); + + public ngOnInit(): void { + super.ngOnInit(); + this.valueSubject.pipe(debounceTime(this.debounceMs)).subscribe((val) => { + this.setInnerValueAndNotify(val) + }); + } + + public onValueChange(value: string): void { + this.valueSubject.next(value); + } }