Skip to content

Commit 9c8ca33

Browse files
committed
fix(grid): fix date filtering and chip commit #6594
1 parent a10d42e commit 9c8ca33

File tree

3 files changed

+88
-33
lines changed

3 files changed

+88
-33
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,11 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
444444
}
445445
requestAnimationFrame(() => {
446446
const focusedElement = document.activeElement;
447-
if (focusedElement.className === 'igx-chip__remove') {
447+
448+
if (focusedElement.className === 'igx-chip__remove' || focusedElement.tagName === 'IGX-DAY-ITEM') {
448449
return;
449450
}
451+
450452
if (!(focusedElement && this.inputGroup.nativeElement.contains(focusedElement))
451453
&& this.dropDownConditions.collapsed) {
452454
this.commitInput();
@@ -494,7 +496,6 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
494496
*/
495497
public onDateSelected(value: Date) {
496498
this.value = value;
497-
this.commitInput();
498499
}
499500

500501
/**

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

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,37 +2667,6 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
26672667
expect(dropdownList).toBeNull();
26682668
}));
26692669

2670-
it('Should commit the input and new chip after picking date from calendar for filtering.', fakeAsync(() => {
2671-
// Click date filter chip to show filter row.
2672-
const filterCells = fix.debugElement.queryAll(By.directive(IgxGridFilteringCellComponent));
2673-
const dateFilterCell = filterCells.find((fc) => fc.componentInstance.column.field === 'ReleaseDate');
2674-
const dateFilterCellChip = dateFilterCell.query(By.directive(IgxChipComponent));
2675-
dateFilterCellChip.nativeElement.click();
2676-
tick(100);
2677-
fix.detectChanges();
2678-
2679-
// Click input to open calendar.
2680-
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
2681-
const input = filteringRow.query(By.directive(IgxInputDirective));
2682-
input.nativeElement.click();
2683-
tick(100);
2684-
fix.detectChanges();
2685-
2686-
// Click the today date.
2687-
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
2688-
const calendar = outlet.getElementsByClassName('igx-calendar')[0];
2689-
const todayDayItem = calendar.querySelector('.igx-calendar__date--current');
2690-
(<HTMLElement>todayDayItem).click();
2691-
tick(100);
2692-
fix.detectChanges();
2693-
2694-
// Verify the chip and input are committed.
2695-
const activeFiltersArea = filteringRow.query(By.css('.igx-grid__filtering-row-main'));
2696-
const activeFilterChip = activeFiltersArea.query(By.directive(IgxChipComponent));
2697-
expect((<IgxChipComponent>activeFilterChip.componentInstance).selected).toBe(false, 'chip is not committed');
2698-
expect((<IgxInputDirective>input.componentInstance).value).toBeNull('input value is present and not committed');
2699-
}));
2700-
27012670
it('Should correctly change resource strings for filter row.', fakeAsync(() => {
27022671
fix = TestBed.createComponent(IgxGridFilteringComponent);
27032672
grid = fix.componentInstance.grid;
@@ -3474,6 +3443,84 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
34743443
const headerChip = GridFunctions.getFilterChipsForColumn('ProductName', fix);
34753444
expect(headerChip.length).toBe(1);
34763445
}));
3446+
3447+
fit('Should commit the input and new chip after focus out and should edit chip without creating new one.', fakeAsync(() => {
3448+
// Click date filter chip to show filter row.
3449+
const filterCells = fix.debugElement.queryAll(By.directive(IgxGridFilteringCellComponent));
3450+
const dateFilterCell = filterCells.find((fc) => fc.componentInstance.column.field === 'ReleaseDate');
3451+
const dateFilterCellChip = dateFilterCell.query(By.directive(IgxChipComponent));
3452+
dateFilterCellChip.nativeElement.click();
3453+
tick(100);
3454+
fix.detectChanges();
3455+
3456+
// Click input to open calendar.
3457+
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
3458+
const input = filteringRow.query(By.directive(IgxInputDirective));
3459+
input.nativeElement.click();
3460+
tick(100);
3461+
fix.detectChanges();
3462+
3463+
// Click the today date.
3464+
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
3465+
let calendar = outlet.getElementsByClassName('igx-calendar')[0];
3466+
const todayDayItem = calendar.querySelector('.igx-calendar__date--current');
3467+
(<HTMLElement>todayDayItem).click();
3468+
tick(100);
3469+
fix.detectChanges();
3470+
3471+
// Focus out
3472+
clickElemAndBlur(dateFilterCellChip, input);
3473+
tick(200);
3474+
fix.detectChanges();
3475+
expect(dateFilterCellChip.componentInstance.selected).toBeFalsy('initial chip is not committed');
3476+
expect((<IgxInputDirective>input.componentInstance).value).toBeNull('initial input value is present and not committed');
3477+
3478+
// Select our newly added chip to edit it
3479+
const chip = GridFunctions.getFilterConditionChip(fix, 0);
3480+
chip.click();
3481+
tick(200);
3482+
fix.detectChanges();
3483+
3484+
// Open calendar
3485+
input.nativeElement.click();
3486+
tick(100);
3487+
fix.detectChanges();
3488+
3489+
calendar = outlet.getElementsByClassName('igx-calendar')[0];
3490+
3491+
// View years
3492+
const yearView = calendar.querySelectorAll('.igx-calendar-picker__date')[1];
3493+
(<HTMLElement>yearView).click();
3494+
tick(100);
3495+
fix.detectChanges();
3496+
3497+
// Select the first year
3498+
const firstYear = calendar.querySelectorAll('.igx-calendar__year')[0];
3499+
(<HTMLElement>firstYear).click();
3500+
tick(100);
3501+
fix.detectChanges();
3502+
3503+
// Select the first day
3504+
const firstDayItem = calendar.querySelector('.igx-calendar__date');
3505+
(<HTMLElement>firstDayItem).click();
3506+
tick(100);
3507+
fix.detectChanges();
3508+
3509+
// Focus out
3510+
clickElemAndBlur(dateFilterCellChip, input);
3511+
tick(200);
3512+
fix.detectChanges();
3513+
expect(dateFilterCellChip.componentInstance.selected).toBeFalsy();
3514+
3515+
// Check if we still have only one committed chip
3516+
const activeFiltersArea = filteringRow.query(By.css('.igx-grid__filtering-row-main'));
3517+
const activeFilterChip = activeFiltersArea.query(By.directive(IgxChipComponent));
3518+
const chipsLength = GridFunctions.getAllFilterConditionChips(fix).length;
3519+
3520+
expect(chipsLength).toBe(1, 'there is more than one chip');
3521+
expect((<IgxChipComponent>activeFilterChip.componentInstance).selected).toBe(false, 'chip is not committed');
3522+
expect((<IgxInputDirective>input.componentInstance).value).toBeNull('input value is present and not committed');
3523+
}));
34773524
});
34783525
describe(null, () => {
34793526
let fix, grid;

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,13 @@ export class GridFunctions {
918918
return conditionChips[index];
919919
}
920920

921+
public static getAllFilterConditionChips(fix) {
922+
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
923+
const conditionChips = GridFunctions.sortNativeElementsHorizontally(
924+
filterUIRow.queryAll(By.directive(IgxChipComponent)).map((ch) => ch.nativeElement));
925+
return conditionChips;
926+
}
927+
921928
public static getFilterRowInputCommitIcon(fix) {
922929
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
923930
const inputGroup = filterUIRow.query(By.css('igx-input-group'));

0 commit comments

Comments
 (0)