Skip to content

Commit 40e2574

Browse files
Merge pull request #5749 from IgniteUI/astaev/issue5627-8.1.x
fix(filtering): Make unary condition committable #5627
2 parents 62346a0 + 6c9b8e1 commit 40e2574

File tree

4 files changed

+53
-13
lines changed

4 files changed

+53
-13
lines changed

projects/igniteui-angular/src/lib/grids/filtering/grid-filtering-row.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
(onSelection)="onDateSelected($event)"
5151
(onClose)="datePickerClose()">
5252
<ng-template igxDatePickerTemplate let-openDialog="openDialog">
53-
<igx-input-group #dropDownTarget type="box" [displayDensity]="'compact'" [supressInputAutofocus]="true">
53+
<igx-input-group #inputGroup type="box" [displayDensity]="'compact'" [supressInputAutofocus]="true" (focusout)="onInputGroupFocusout()">
5454
<igx-prefix #inputGroupPrefix
5555
tabindex="0"
5656
(click)="toggleConditionsDropDown(inputGroupPrefix)"
@@ -61,7 +61,7 @@
6161
<input #input
6262
igxInput
6363
tabindex="0"
64-
(click)="expression.condition.isUnary ? noop() : openDialog(dropDownTarget.element.nativeElement)"
64+
(click)="expression.condition.isUnary ? noop() : openDialog(inputGroup.element.nativeElement)"
6565
[placeholder]="placeholder"
6666
autocomplete="off"
6767
[value]="value | igxdate: filteringService.grid.locale"

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import {
1010
ElementRef,
1111
HostBinding,
1212
HostListener,
13-
ChangeDetectionStrategy
13+
ChangeDetectionStrategy,
14+
ViewRef
1415
} from '@angular/core';
1516
import { DataType } from '../../data-operations/data-util';
1617
import { IgxColumnComponent } from '../column.component';
@@ -437,11 +438,15 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
437438
* Event handler for focusout on the input group.
438439
*/
439440
public onInputGroupFocusout() {
440-
if (!this.value && this.value !== 0) {
441+
if (!this.value && this.value !== 0 &&
442+
this.expression.condition && !this.expression.condition.isUnary) {
441443
return;
442444
}
443445
requestAnimationFrame(() => {
444446
const focusedElement = document.activeElement;
447+
if (focusedElement.className === 'igx-chip__remove') {
448+
return;
449+
}
445450
if (!(focusedElement && this.inputGroup.nativeElement.contains(focusedElement))
446451
&& this.dropDownConditions.collapsed) {
447452
this.commitInput();
@@ -481,7 +486,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
481486
/*
482487
* noop
483488
*/
484-
public noop() {}
489+
public noop() { }
485490

486491
/**
487492
* Event handler for date picker's selection.
@@ -531,7 +536,8 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
531536

532537
public onChipPointerdown(args, chip: IgxChipComponent) {
533538
const activeElement = document.activeElement;
534-
this._cancelChipClick = chip.selected && activeElement && this.inputGroup.nativeElement.contains(activeElement);
539+
this._cancelChipClick = chip.selected && activeElement &&
540+
this.inputGroup.nativeElement.contains(activeElement);
535541
}
536542

537543
public onChipClick(args, item: ExpressionUI) {
@@ -648,7 +654,8 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
648654
this.showArrows = this.chipsAreaWidth >= containerWidth && this.isColumnFiltered;
649655

650656
// TODO: revise the cdr.detectChanges() usage here
651-
this.cdr.detectChanges();
657+
if (!(this.cdr as ViewRef).destroyed) {
658+
this.cdr.detectChanges(); }
652659
}
653660
});
654661
}

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-ui.spec.ts

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1818,9 +1818,10 @@ describe('IgxGrid - Filtering Row UI actions', () => {
18181818
dateCellChip.nativeElement.click();
18191819
fix.detectChanges();
18201820

1821-
GridFunctions.filterBy('Today', '', fix);
1821+
GridFunctions.filterBy('Today', null, fix);
1822+
tick(100);
18221823
expect(grid.rowList.length).toEqual(1);
1823-
GridFunctions.filterBy('Null', '', fix);
1824+
GridFunctions.filterBy('Null', null, fix);
18241825
expect(grid.rowList.length).toEqual(0);
18251826
}));
18261827

@@ -3386,8 +3387,38 @@ describe('IgxGrid - Filtering Row UI actions', () => {
33863387
expect(fix.debugElement.query(By.css(FILTER_UI_ROW))).toBeNull();
33873388
GridFunctions.verifyColumnIsHidden(prodNameCol, true , 5);
33883389
}));
3389-
});
33903390

3391+
it('Unary conditions should be committable', fakeAsync (() => {
3392+
grid.height = '700px';
3393+
fix.detectChanges();
3394+
3395+
const prodNameCol = grid.columns.find((col) => col.field === 'ProductName');
3396+
GridFunctions.clickFilterCellChip(fix, 'ProductName');
3397+
fix.detectChanges();
3398+
3399+
// Check that the filterRow is opened
3400+
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
3401+
GridFunctions.openFilterDD(fix.debugElement);
3402+
const dropdownList = fix.debugElement.query(By.css('div.igx-drop-down__list.igx-toggle'));
3403+
GridFunctions.selectFilteringCondition('Empty', dropdownList);
3404+
fix.detectChanges();
3405+
tick(16);
3406+
3407+
const chip = filterUIRow.query(By.directive(IgxChipComponent));
3408+
const input = filterUIRow.query(By.directive(IgxInputDirective));
3409+
expect(chip.componentInstance.selected).toBeTruthy();
3410+
3411+
clickElemAndBlur(chip, input);
3412+
fix.detectChanges();
3413+
tick(100);
3414+
expect(chip.componentInstance.selected).toBeFalsy();
3415+
3416+
GridFunctions.clickChip(chip);
3417+
fix.detectChanges();
3418+
tick(100);
3419+
expect(chip.componentInstance.selected).toBeTruthy();
3420+
}));
3421+
});
33913422
describe(null, () => {
33923423
let fix, grid;
33933424
beforeEach(fakeAsync(() => {
@@ -6293,8 +6324,8 @@ function clickElemAndBlur(clickElem, blurElem) {
62936324
const elementRect = clickElem.nativeElement.getBoundingClientRect();
62946325
UIInteractions.simulatePointerEvent('pointerdown', clickElem.nativeElement, elementRect.left, elementRect.top);
62956326
blurElem.nativeElement.blur();
6296-
blurElem.nativeElement.dispatchEvent(new FocusEvent('focusout', {bubbles: true}));
62976327
(clickElem as DebugElement).nativeElement.focus();
6328+
blurElem.nativeElement.dispatchEvent(new FocusEvent('focusout', {bubbles: true}));
62986329
UIInteractions.simulatePointerEvent('pointerup', clickElem.nativeElement, elementRect.left, elementRect.top);
62996330
UIInteractions.simulateMouseEvent('click', clickElem.nativeElement, 10 , 10);
63006331
}

projects/igniteui-angular/src/lib/test-utils/grid-functions.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ export class GridFunctions {
423423

424424
const ddList = fix.debugElement.query(By.css('div.igx-drop-down__list.igx-toggle'));
425425
this.selectFilteringCondition(condition, ddList);
426-
427-
this.applyFilter(value, fix);
426+
// fix.detectChanges();
427+
tick(100);
428+
this.applyFilter(value, fix);
429+
tick(100);
428430
}
429431

430432
public static typeValueInFilterRowInput(value: string, fix) {

0 commit comments

Comments
 (0)