Skip to content

Commit a2b7d1d

Browse files
Merge pull request #7065 from IgniteUI/ibarakov/fix-6594-9.0.x
fix(filter-ui): Fix date filtering and chip commit #6594
2 parents 5bb752a + 20a90cb commit a2b7d1d

File tree

4 files changed

+102
-32
lines changed

4 files changed

+102
-32
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@
6767
[value]="value | igxdate: filteringService.grid.locale"
6868
[readonly]="true"
6969
(keydown)="onInputKeyDown($event)"/>
70-
<igx-suffix *ngIf="value" (keydown)="onClearKeyDown($event)" (click)="clearInput()" tabindex="0">
71-
<igx-icon>clear</igx-icon>
70+
<igx-suffix *ngIf="value">
71+
<igx-icon (keydown)="onCommitKeyDown($event)" (click)="onCommitClick()" tabindex="0">done</igx-icon>
72+
<igx-icon (keydown)="onClearKeyDown($event)" (click)="clearInput()" tabindex="0">clear</igx-icon>
7273
</igx-suffix>
7374
</igx-input-group>
7475
</ng-template>

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

Lines changed: 4 additions & 4 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
/**
@@ -543,11 +544,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
543544

544545
public onChipClick(args, item: ExpressionUI) {
545546
if (this._cancelChipClick) {
547+
this._cancelChipClick = false;
546548
return;
547549
}
548550

549-
this._cancelChipClick = false;
550-
551551
this.expressionsList.forEach(ex => ex.isSelected = false);
552552

553553
this.toggleChip(item);

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

Lines changed: 88 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,31 +1355,6 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
13551355
verifyFilterRowUI(input, close, reset);
13561356
}));
13571357

1358-
it('Should commit the input and new chip after picking date from calendar for filtering.', fakeAsync(() => {
1359-
GridFunctions.clickFilterCellChip(fix, 'ReleaseDate');
1360-
1361-
// Click input to open calendar.
1362-
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
1363-
const input = filteringRow.query(By.directive(IgxInputDirective));
1364-
input.triggerEventHandler('click', null);
1365-
tick(100);
1366-
fix.detectChanges();
1367-
1368-
// Click the today date.
1369-
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
1370-
const calendar = outlet.getElementsByClassName('igx-calendar')[0];
1371-
const todayDayItem = calendar.querySelector('.igx-calendar__date--current');
1372-
(<HTMLElement>todayDayItem).click();
1373-
tick(200);
1374-
fix.detectChanges();
1375-
1376-
// Verify the chip and input are committed.
1377-
const filterChip = filteringRow.query(By.directive(IgxChipComponent));
1378-
expect(filterChip).toBeTruthy();
1379-
expect(filterChip.componentInstance.selected).toBeFalsy();
1380-
expect(input.nativeElement.value).toEqual('');
1381-
}));
1382-
13831358
it('Should navigate keyboard focus correctly between the filter row and the grid cells.', fakeAsync(() => {
13841359
GridFunctions.clickFilterCellChip(fix, 'ProductName');
13851360

@@ -1986,6 +1961,94 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
19861961
const headerChip = GridFunctions.getFilterChipsForColumn('ProductName', fix);
19871962
expect(headerChip.length).toBe(1);
19881963
}));
1964+
1965+
it('Should commit the input and new chip after focus out and should edit chip without creating new one.', fakeAsync(() => {
1966+
// Click date filter chip to show filter row.
1967+
const dateFilterCellChip = GridFunctions.getFilterChipsForColumn('ReleaseDate', fix)[0];
1968+
dateFilterCellChip.nativeElement.click();
1969+
tick(100);
1970+
fix.detectChanges();
1971+
1972+
// Click input to open calendar.
1973+
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
1974+
const inputDebugElement = filteringRow.query(By.directive(IgxInputDirective));
1975+
const input = inputDebugElement.nativeElement;
1976+
input.click();
1977+
tick(100);
1978+
fix.detectChanges();
1979+
1980+
// Click the today date.
1981+
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
1982+
let calendar = outlet.getElementsByClassName('igx-calendar')[0];
1983+
const todayDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date--current');
1984+
todayDayItem.focus();
1985+
todayDayItem.click();
1986+
grid.filteringRow.onInputGroupFocusout();
1987+
tick(100);
1988+
fix.detectChanges();
1989+
1990+
// Verify the newly added chip is selected.
1991+
const chip = GridFunctions.getFilterConditionChip(fix, 0);
1992+
const chipDiv = chip.querySelector('.igx-chip__item');
1993+
1994+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(true, 'initial chip is committed');
1995+
1996+
// Focus out
1997+
grid.nativeElement.focus();
1998+
grid.filteringRow.onInputGroupFocusout();
1999+
tick(200);
2000+
fix.detectChanges();
2001+
2002+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'initial chip is not committed');
2003+
expect(input.value).toBe('', 'initial input value is present and not committed');
2004+
2005+
chip.click();
2006+
tick(200);
2007+
fix.detectChanges();
2008+
2009+
// Open calendar
2010+
input.click();
2011+
tick(100);
2012+
fix.detectChanges();
2013+
2014+
calendar = outlet.getElementsByClassName('igx-calendar')[0];
2015+
2016+
// View years
2017+
const yearView: HTMLElement = calendar.querySelectorAll('.igx-calendar-picker__date')[1] as HTMLElement;
2018+
yearView.click();
2019+
tick(100);
2020+
fix.detectChanges();
2021+
2022+
// Select the first year
2023+
const firstYear: HTMLElement = calendar.querySelectorAll('.igx-calendar__year')[0] as HTMLElement;
2024+
firstYear.click();
2025+
tick(100);
2026+
fix.detectChanges();
2027+
2028+
// Select the first day
2029+
const firstDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date');
2030+
firstDayItem.focus();
2031+
firstDayItem.click();
2032+
grid.filteringRow.onInputGroupFocusout();
2033+
tick(100);
2034+
fix.detectChanges();
2035+
2036+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(true, 'chip is committed');
2037+
2038+
// Focus out
2039+
grid.nativeElement.focus();
2040+
grid.filteringRow.onInputGroupFocusout();
2041+
tick(200);
2042+
fix.detectChanges();
2043+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is selected');
2044+
2045+
// Check if we still have only one committed chip
2046+
const chipsLength = GridFunctions.getAllFilterConditionChips(fix).length;
2047+
2048+
expect(chipsLength).toBe(1, 'there is more than one chip');
2049+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is not committed');
2050+
expect(input.value).toBe('', 'input value is present and not committed');
2051+
}));
19892052
});
19902053

19912054
describe('Integration scenarios', () => {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,16 @@ export class GridFunctions {
11481148
}
11491149

11501150
public static getFilterConditionChip(fix, index) {
1151+
const conditionChips = this.getAllFilterConditionChips(fix);
1152+
1153+
return conditionChips[index];
1154+
}
1155+
1156+
public static getAllFilterConditionChips(fix) {
11511157
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
11521158
const conditionChips = GridFunctions.sortNativeElementsHorizontally(
11531159
filterUIRow.queryAll(By.directive(IgxChipComponent)).map((ch) => ch.nativeElement));
1154-
return conditionChips[index];
1160+
return conditionChips;
11551161
}
11561162

11571163
public static getFilterRowPrefix(fix): DebugElement {

0 commit comments

Comments
 (0)