Skip to content

Commit 411c1c1

Browse files
authored
Merge branch '9.0.x' into dmdimitrov/issue7480-9.0.x
2 parents e900ee5 + d6d63cf commit 411c1c1

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,31 @@ describe('IgxAutocomplete', () => {
593593
UIInteractions.triggerKeyDownEvtUponElem('enter', input.nativeElement, true);
594594
expect(fixture.componentInstance.townSelected).toBe('s');
595595
}));
596+
it('Should trigger onItemSelected only once when the event is cancelled (issue #7483)', fakeAsync(() => {
597+
spyOn(autocomplete.onItemSelected, 'emit').and.callThrough();
598+
599+
fixture.componentInstance.onItemSelected = (args) => { args.cancel = true; };
600+
UIInteractions.setInputElementValue(input, 's', fixture);
601+
fixture.detectChanges();
602+
tick();
603+
UIInteractions.triggerKeyDownEvtUponElem('enter', input.nativeElement, true);
604+
expect(fixture.componentInstance.townSelected).toBe('s');
605+
tick();
606+
fixture.detectChanges();
607+
expect(autocomplete.onItemSelected.emit).toHaveBeenCalledTimes(1);
608+
expect(autocomplete.onItemSelected.emit).toHaveBeenCalledWith({ value: 'Sofia', cancel: true });
609+
610+
fixture.componentInstance.onItemSelected = (args) => { args.cancel = true; };
611+
UIInteractions.setInputElementValue(input, 's', fixture);
612+
fixture.detectChanges();
613+
tick();
614+
UIInteractions.triggerKeyDownEvtUponElem('enter', input.nativeElement, true);
615+
expect(fixture.componentInstance.townSelected).toBe('s');
616+
tick();
617+
fixture.detectChanges();
618+
expect(autocomplete.onItemSelected.emit).toHaveBeenCalledTimes(2);
619+
expect(autocomplete.onItemSelected.emit).toHaveBeenCalledWith({ value: 'Sofia', cancel: true });
620+
}));
596621
it('Should call onInput/open/close methods properly', fakeAsync(() => {
597622
let startsWith = 'g';
598623
spyOn(autocomplete, 'onInput').and.callThrough();

projects/igniteui-angular/src/lib/directives/autocomplete/autocomplete.directive.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
NgModule, ElementRef, HostListener, ChangeDetectorRef, OnDestroy } from '@angular/core';
44
import { NgModel, FormControlName } from '@angular/forms';
55
import { CommonModule } from '@angular/common';
6-
import { Subject } from 'rxjs';
6+
import { Subject, Subscription } from 'rxjs';
77
import { first, takeUntil } from 'rxjs/operators';
88
import { CancelableEventArgs, IBaseEventArgs } from '../../core/utils';
99
import { OverlaySettings, AbsoluteScrollStrategy, IScrollStrategy, IPositionStrategy, AutoPositionStrategy } from '../../services/index';
@@ -68,6 +68,9 @@ export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective
6868
excludePositionTarget: true
6969
};
7070

71+
/** @hidden @internal */
72+
private subscriptions: Subscription[] = [];
73+
7174
protected id: string;
7275
protected dropDownOpened$ = new Subject<boolean>();
7376
protected get model() {
@@ -280,9 +283,18 @@ export class IgxAutocompleteDirective extends IgxDropDownItemNavigationDirective
280283
// If no drop-down width is set, the drop-down will be as wide as the autocomplete input;
281284
this.target.width = this.target.width || (this.parentElement.clientWidth + 'px');
282285
this.target.open(this.settings);
283-
this.target.onSelection.pipe(takeUntil(this.dropDownOpened$)).subscribe(this.select);
284-
this.target.onOpened.pipe(first()).subscribe(this.highlightFirstItem);
285-
this.target.children.changes.pipe(takeUntil(this.dropDownOpened$)).subscribe(this.highlightFirstItem);
286+
287+
// unsubscribe from previous subscriptions, before creating new subscriptions.
288+
this.unsubscribe();
289+
290+
this.subscriptions.push(this.target.onSelection.pipe(takeUntil(this.dropDownOpened$)).subscribe(this.select));
291+
this.subscriptions.push(this.target.onOpened.pipe(first()).subscribe(this.highlightFirstItem));
292+
this.subscriptions.push(this.target.children.changes.pipe(takeUntil(this.dropDownOpened$)).subscribe(this.highlightFirstItem));
293+
}
294+
295+
/** @hidden @internal */
296+
private unsubscribe() {
297+
this.subscriptions.forEach(subscription => subscription.unsubscribe());
286298
}
287299

288300
private get collapsed(): boolean {

projects/igniteui-angular/src/lib/grids/api.service.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,6 @@ export class GridBaseAPIService <T extends IgxGridBaseDirective & GridType> {
540540
return false;
541541
}
542542

543-
public atInexistingPage(): boolean {
544-
return this.grid.totalPages - 1 > this.grid.page;
545-
}
546-
547543
public get_row_expansion_state(record: any): boolean {
548544
const grid = this.grid;
549545
const states = grid.expansionStates;

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,12 +2639,6 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
26392639
this.summaryService.clearSummaryCache();
26402640
this._pipeTrigger++;
26412641
this.notifyChanges();
2642-
if (this.transactions.getAggregatedChanges(false).length === 0) {
2643-
// Needs better check, calling 'transactions.clear()' will also trigger this
2644-
if (this.gridAPI.atInexistingPage()) {
2645-
this.page--;
2646-
}
2647-
}
26482642
});
26492643

26502644
this.resizeNotify.pipe(destructor, filter(() => !this._init), throttleTime(100))

src/app/grid-row-edit/grid-row-edit-sample.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ <h4>Cancel Grid Edit Events</h4>
9191
</div>
9292
<app-grid-with-transactions>
9393
<igx-grid #gridRowEditTransaction [data]="data" [primaryKey]="'ProductID'" width="900px" height="700px"
94-
[rowEditable]="true" [paging]="true" [perPage]="10" (onRowEdit)="rowEditDone($event)"
94+
[rowEditable]="true" [paging]="true" [perPage]="5" (onRowEdit)="rowEditDone($event)"
9595
(onRowEditCancel)="rowEditCancel($event)" (onRowEditEnter)="rowEditEnter($event)"
9696
(onCellEditEnter)="cellEnterEditMode($event)" (onCellEdit)="cellEditDone($event)"
9797
(onCellEditCancel)="cellEditCancel($event)">

0 commit comments

Comments
 (0)