Skip to content

Commit f3c4821

Browse files
authored
Merge pull request #7044 from IgniteUI/ibarakov/fix-6594-8.2.x
fix(grid): fix date filtering and chip commit #6594
2 parents f7a414d + e6a7ac1 commit f3c4821

File tree

4 files changed

+108
-44
lines changed

4 files changed

+108
-44
lines changed

projects/igniteui-angular/src/lib/grids/filtering/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/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: 94 additions & 37 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,88 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
34743443
const headerChip = GridFunctions.getFilterChipsForColumn('ProductName', fix);
34753444
expect(headerChip.length).toBe(1);
34763445
}));
3446+
3447+
it('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 dateFilterCellChip = GridFunctions.getFilterChipsForColumn('ReleaseDate', fix)[0];
3450+
dateFilterCellChip.nativeElement.click();
3451+
tick(100);
3452+
fix.detectChanges();
3453+
3454+
// Click input to open calendar.
3455+
const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
3456+
const inputDebugElement = filteringRow.query(By.directive(IgxInputDirective));
3457+
const input = inputDebugElement.nativeElement;
3458+
input.click();
3459+
tick(100);
3460+
fix.detectChanges();
3461+
3462+
// Click the today date.
3463+
const outlet = document.getElementsByClassName('igx-grid__outlet')[0];
3464+
let calendar = outlet.getElementsByClassName('igx-calendar')[0];
3465+
const todayDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date--current');
3466+
clickHtmlElemAndBlur(todayDayItem, inputDebugElement);
3467+
tick(100);
3468+
fix.detectChanges();
3469+
3470+
// Verify the newly added chip is selected.
3471+
const chip = GridFunctions.getFilterConditionChip(fix, 0);
3472+
const chipDiv = chip.querySelector('.igx-chip__item');
3473+
3474+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(true, 'initial chip is committed');
3475+
3476+
// Focus out
3477+
clickHtmlElemAndBlur(chip, inputDebugElement);
3478+
tick(200);
3479+
fix.detectChanges();
3480+
3481+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'initial chip is not committed');
3482+
expect(input.value).toBe('', 'initial input value is present and not committed');
3483+
3484+
chip.click();
3485+
tick(200);
3486+
fix.detectChanges();
3487+
3488+
// Open calendar
3489+
input.click();
3490+
tick(100);
3491+
fix.detectChanges();
3492+
3493+
calendar = outlet.getElementsByClassName('igx-calendar')[0];
3494+
3495+
// View years
3496+
const yearView: HTMLElement = calendar.querySelectorAll('.igx-calendar-picker__date')[1] as HTMLElement;
3497+
yearView.click();
3498+
tick(100);
3499+
fix.detectChanges();
3500+
3501+
// Select the first year
3502+
const firstYear: HTMLElement = calendar.querySelectorAll('.igx-calendar__year')[0] as HTMLElement;
3503+
firstYear.click();
3504+
tick(100);
3505+
fix.detectChanges();
3506+
3507+
// Select the first day
3508+
const firstDayItem: HTMLElement = calendar.querySelector('.igx-calendar__date');
3509+
clickHtmlElemAndBlur(firstDayItem, inputDebugElement);
3510+
tick(100);
3511+
fix.detectChanges();
3512+
3513+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(true, 'chip is committed');
3514+
3515+
// Focus out
3516+
clickHtmlElemAndBlur(chip, inputDebugElement);
3517+
tick(200);
3518+
fix.detectChanges();
3519+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is selected');
3520+
3521+
// Check if we still have only one committed chip
3522+
const chipsLength = GridFunctions.getAllFilterConditionChips(fix).length;
3523+
3524+
expect(chipsLength).toBe(1, 'there is more than one chip');
3525+
expect(chipDiv.classList.contains('igx-chip__item--selected')).toBe(false, 'chip is not committed');
3526+
expect(input.value).toBe('', 'input value is present and not committed');
3527+
}));
34773528
});
34783529
describe(null, () => {
34793530
let fix, grid;
@@ -6491,12 +6542,18 @@ function verifyChipVisibility(fix, index: number, shouldBeFullyVisible: boolean)
64916542
.toBe(shouldBeFullyVisible, 'chip[' + index + '] visibility is incorrect');
64926543
}
64936544

6494-
function clickElemAndBlur(clickElem, blurElem) {
6495-
const elementRect = clickElem.nativeElement.getBoundingClientRect();
6496-
UIInteractions.simulatePointerEvent('pointerdown', clickElem.nativeElement, elementRect.left, elementRect.top);
6545+
function clickElemAndBlur(clickElem: DebugElement, blurElem: DebugElement) {
6546+
const clickHtmlElem = clickElem.nativeElement;
6547+
6548+
clickHtmlElemAndBlur(clickHtmlElem, blurElem);
6549+
}
6550+
6551+
function clickHtmlElemAndBlur(clickElem: HTMLElement, blurElem: DebugElement) {
6552+
const elementRect = clickElem.getBoundingClientRect();
6553+
UIInteractions.simulatePointerEvent('pointerdown', clickElem, elementRect.left, elementRect.top);
64976554
blurElem.nativeElement.blur();
6498-
(clickElem as DebugElement).nativeElement.focus();
6555+
clickElem.focus();
64996556
blurElem.nativeElement.dispatchEvent(new FocusEvent('focusout', { bubbles: true }));
6500-
UIInteractions.simulatePointerEvent('pointerup', clickElem.nativeElement, elementRect.left, elementRect.top);
6501-
UIInteractions.simulateMouseEvent('click', clickElem.nativeElement, 10, 10);
6557+
UIInteractions.simulatePointerEvent('pointerup', clickElem, elementRect.left, elementRect.top);
6558+
UIInteractions.simulateMouseEvent('click', clickElem, 10, 10);
65026559
}

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
@@ -912,10 +912,16 @@ export class GridFunctions {
912912
}
913913

914914
public static getFilterConditionChip(fix, index) {
915+
const conditionChips = this.getAllFilterConditionChips(fix);
916+
917+
return conditionChips[index];
918+
}
919+
920+
public static getAllFilterConditionChips(fix) {
915921
const filterUIRow = fix.debugElement.query(By.css(FILTER_UI_ROW));
916922
const conditionChips = GridFunctions.sortNativeElementsHorizontally(
917923
filterUIRow.queryAll(By.directive(IgxChipComponent)).map((ch) => ch.nativeElement));
918-
return conditionChips[index];
924+
return conditionChips;
919925
}
920926

921927
public static getFilterRowInputCommitIcon(fix) {

0 commit comments

Comments
 (0)