Skip to content

Commit c36571d

Browse files
committed
Merge branch 'master' of https://github.com/IgniteUI/igniteui-angular into ddincheva/focuslessKBNav
2 parents 55ab336 + 5cc772c commit c36571d

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
@@ -425,9 +425,11 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
425425
}
426426
requestAnimationFrame(() => {
427427
const focusedElement = document.activeElement;
428-
if (focusedElement.className === 'igx-chip__remove') {
428+
429+
if (focusedElement.className === 'igx-chip__remove' || focusedElement.tagName === 'IGX-DAY-ITEM') {
429430
return;
430431
}
432+
431433
if (!(focusedElement && this.inputGroup.nativeElement.contains(focusedElement))
432434
&& this.dropDownConditions.collapsed) {
433435
this.commitInput();
@@ -475,7 +477,6 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
475477
*/
476478
public onDateSelected(value: Date) {
477479
this.value = value;
478-
this.commitInput();
479480
}
480481

481482
/**
@@ -524,11 +525,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
524525

525526
public onChipClick(args, item: ExpressionUI) {
526527
if (this._cancelChipClick) {
528+
this._cancelChipClick = false;
527529
return;
528530
}
529531

530-
this._cancelChipClick = false;
531-
532532
this.expressionsList.forEach(ex => ex.isSelected = false);
533533

534534
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
@@ -1357,31 +1357,6 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
13571357
verifyFilterRowUI(input, close, reset);
13581358
}));
13591359

1360-
it('Should commit the input and new chip after picking date from calendar for filtering.', fakeAsync(() => {
1361-
GridFunctions.clickFilterCellChip(fix, 'ReleaseDate');
1362-
1363-
// Click input to open calendar.
1364-
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
1365-
const input = filteringRow.query(By.directive(IgxInputDirective));
1366-
input.triggerEventHandler('click', null);
1367-
tick(100);
1368-
fix.detectChanges();
1369-
1370-
// Click the today date.
1371-
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
1372-
const calendar = outlet.getElementsByClassName('igx-calendar')[0];
1373-
const todayDayItem = calendar.querySelector('.igx-calendar__date--current');
1374-
(<HTMLElement>todayDayItem).click();
1375-
tick(200);
1376-
fix.detectChanges();
1377-
1378-
// Verify the chip and input are committed.
1379-
const filterChip = filteringRow.query(By.directive(IgxChipComponent));
1380-
expect(filterChip).toBeTruthy();
1381-
expect(filterChip.componentInstance.selected).toBeFalsy();
1382-
expect(input.nativeElement.value).toEqual('');
1383-
}));
1384-
13851360
it('Should navigate keyboard focus correctly between the filter row and the grid cells.', fakeAsync(() => {
13861361
pending('Should be fixed with headers navigation');
13871362
GridFunctions.clickFilterCellChip(fix, 'ProductName');
@@ -1991,6 +1966,94 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
19911966
const headerChip = GridFunctions.getFilterChipsForColumn('ProductName', fix);
19921967
expect(headerChip.length).toBe(1);
19931968
}));
1969+
1970+
it('Should commit the input and new chip after focus out and should edit chip without creating new one.', fakeAsync(() => {
1971+
// Click date filter chip to show filter row.
1972+
const dateFilterCellChip = GridFunctions.getFilterChipsForColumn('ReleaseDate', fix)[0];
1973+
dateFilterCellChip.nativeElement.click();
1974+
tick(100);
1975+
fix.detectChanges();
1976+
1977+
// Click input to open calendar.
1978+
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
1979+
const inputDebugElement = filteringRow.query(By.directive(IgxInputDirective));
1980+
const input = inputDebugElement.nativeElement;
1981+
input.click();
1982+
tick(100);
1983+
fix.detectChanges();
1984+
1985+
// Click the today date.
1986+
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
1987+
let calendar = outlet.getElementsByClassName('igx-calendar')[0];
1988+
const todayDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date--current');
1989+
todayDayItem.focus();
1990+
todayDayItem.click();
1991+
grid.filteringRow.onInputGroupFocusout();
1992+
tick(100);
1993+
fix.detectChanges();
1994+
1995+
// Verify the newly added chip is selected.
1996+
const chip = GridFunctions.getFilterConditionChip(fix, 0);
1997+
const chipDiv = chip.querySelector('.igx-chip__item');
1998+
1999+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(true, 'initial chip is committed');
2000+
2001+
// Focus out
2002+
grid.nativeElement.focus();
2003+
grid.filteringRow.onInputGroupFocusout();
2004+
tick(200);
2005+
fix.detectChanges();
2006+
2007+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'initial chip is not committed');
2008+
expect(input.value).toBe('', 'initial input value is present and not committed');
2009+
2010+
chip.click();
2011+
tick(200);
2012+
fix.detectChanges();
2013+
2014+
// Open calendar
2015+
input.click();
2016+
tick(100);
2017+
fix.detectChanges();
2018+
2019+
calendar = outlet.getElementsByClassName('igx-calendar')[0];
2020+
2021+
// View years
2022+
const yearView: HTMLElement = calendar.querySelectorAll('.igx-calendar-picker__date')[1] as HTMLElement;
2023+
yearView.click();
2024+
tick(100);
2025+
fix.detectChanges();
2026+
2027+
// Select the first year
2028+
const firstYear: HTMLElement = calendar.querySelectorAll('.igx-calendar__year')[0] as HTMLElement;
2029+
firstYear.click();
2030+
tick(100);
2031+
fix.detectChanges();
2032+
2033+
// Select the first day
2034+
const firstDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date');
2035+
firstDayItem.focus();
2036+
firstDayItem.click();
2037+
grid.filteringRow.onInputGroupFocusout();
2038+
tick(100);
2039+
fix.detectChanges();
2040+
2041+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(true, 'chip is committed');
2042+
2043+
// Focus out
2044+
grid.nativeElement.focus();
2045+
grid.filteringRow.onInputGroupFocusout();
2046+
tick(200);
2047+
fix.detectChanges();
2048+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is selected');
2049+
2050+
// Check if we still have only one committed chip
2051+
const chipsLength = GridFunctions.getAllFilterConditionChips(fix).length;
2052+
2053+
expect(chipsLength).toBe(1, 'there is more than one chip');
2054+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is not committed');
2055+
expect(input.value).toBe('', 'input value is present and not committed');
2056+
}));
19942057
});
19952058

19962059
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
@@ -1226,10 +1226,16 @@ export class GridFunctions {
12261226
}
12271227

12281228
public static getFilterConditionChip(fix, index) {
1229+
const conditionChips = this.getAllFilterConditionChips(fix);
1230+
1231+
return conditionChips[index];
1232+
}
1233+
1234+
public static getAllFilterConditionChips(fix) {
12291235
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
12301236
const conditionChips = GridFunctions.sortNativeElementsHorizontally(
12311237
filterUIRow.queryAll(By.directive(IgxChipComponent)).map((ch) => ch.nativeElement));
1232-
return conditionChips[index];
1238+
return conditionChips;
12331239
}
12341240

12351241
public static getFilterRowPrefix(fix): DebugElement {

0 commit comments

Comments
 (0)