Skip to content

Commit 8525b79

Browse files
authored
Merge branch 'master' into rkaraivanov/mep-broken-paths-and-exports
2 parents a12cb2c + c26e0c1 commit 8525b79

File tree

3 files changed

+101
-35
lines changed

3 files changed

+101
-35
lines changed

projects/igniteui-angular/grids/core/src/filtering/base/grid-filtering-row.component.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ import {
1212
ChangeDetectionStrategy,
1313
ViewRef,
1414
HostListener,
15-
OnDestroy
15+
OnDestroy,
16+
InjectionToken,
17+
inject,
18+
OnInit
1619
} from '@angular/core';
1720
import { IgxFilteringService } from '../grid-filtering.service';
1821
import { Subject } from 'rxjs';
19-
import { takeUntil } from 'rxjs/operators';
22+
import { debounceTime, takeUntil } from 'rxjs/operators';
2023
import { ExpressionUI } from '../excel-style/common';
2124
import { NgTemplateOutlet, NgClass } from '@angular/common';
2225
import { IgxDropDownComponent, IgxDropDownItemComponent, IgxDropDownItemNavigationDirective, ISelectionEventArgs } from 'igniteui-angular/drop-down';
@@ -28,6 +31,14 @@ import { AbsoluteScrollStrategy, ColumnType, ConnectedPositioningStrategy, DataU
2831
import { IgxTimePickerComponent } from 'igniteui-angular/time-picker';
2932
import { IgxButtonDirective, IgxDateTimeEditorDirective, IgxIconButtonDirective, IgxRippleDirective } from 'igniteui-angular/directives';
3033

34+
/**
35+
* Injection token for setting the debounce time used in filtering row inputs.
36+
* @hidden
37+
*/
38+
export const INPUT_DEBOUNCE_TIME = /*@__PURE__*/new InjectionToken<number>('INPUT_DEBOUNCE_TIME', {
39+
factory: () => 350
40+
});
41+
3142
/**
3243
* @hidden
3344
*/
@@ -58,7 +69,7 @@ import { IgxButtonDirective, IgxDateTimeEditorDirective, IgxIconButtonDirective,
5869
IgxIconButtonDirective
5970
]
6071
})
61-
export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
72+
export class IgxGridFilteringRowComponent implements OnInit, AfterViewInit, OnDestroy {
6273
@Input()
6374
public get column(): ColumnType {
6475
return this._column;
@@ -198,7 +209,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
198209
/** switch to icon buttons when width is below 432px */
199210
private readonly NARROW_WIDTH_THRESHOLD = 432;
200211

212+
private inputSubject: Subject<KeyboardEvent> = new Subject<KeyboardEvent>();
213+
201214
private $destroyer = new Subject<void>();
215+
private readonly DEBOUNCE_TIME = inject(INPUT_DEBOUNCE_TIME);
202216

203217
constructor(
204218
public filteringService: IgxFilteringService,
@@ -207,12 +221,22 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
207221
protected platform: PlatformUtil,
208222
) { }
209223

224+
public ngOnInit(): void {
225+
this.inputSubject.pipe(
226+
debounceTime(this.DEBOUNCE_TIME),
227+
takeUntil(this.$destroyer)
228+
).subscribe(event => {
229+
this.handleInputChange(event);
230+
this.cdr.markForCheck(); // ChangeDetectionStrategy.OnPush is not picking the latest changes of the updated value because of the async pipe + debounce.
231+
});
232+
}
233+
210234
@HostListener('keydown', ['$event'])
211235
public onKeydownHandler(evt: KeyboardEvent) {
212236
if (this.platform.isFilteringKeyCombo(evt)) {
213-
evt.preventDefault();
214-
evt.stopPropagation();
215-
this.close();
237+
evt.preventDefault();
238+
evt.stopPropagation();
239+
this.close();
216240
}
217241
}
218242

@@ -227,10 +251,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
227251
}
228252

229253
this.filteringService.grid.localeChange
230-
.pipe(takeUntil(this.$destroyer))
231-
.subscribe(() => {
232-
this.cdr.markForCheck();
233-
});
254+
.pipe(takeUntil(this.$destroyer))
255+
.subscribe(() => {
256+
this.cdr.markForCheck();
257+
});
234258

235259
requestAnimationFrame(() => this.focusEditElement());
236260
}
@@ -337,6 +361,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
337361
* Event handler for input on the input.
338362
*/
339363
public onInput(eventArgs) {
364+
this.inputSubject.next(eventArgs);
365+
}
366+
367+
private handleInputChange(eventArgs) {
340368
if (!eventArgs) {
341369
return;
342370
}

0 commit comments

Comments
 (0)