Skip to content

Commit 34ef29e

Browse files
zhostigedinakova
andauthored
fix(list): reset pan state and list item position on pancancel event (#9807)
* fix(list): reset pan state and list item position on pancancel event #9105 * test(list): add tests for pancancel event Co-authored-by: INFRAGISTICS\IZhostov <[email protected]> Co-authored-by: Galina Edinakova <[email protected]>
1 parent c8fbbe1 commit 34ef29e

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

projects/igniteui-angular/src/lib/list/list-item.component.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@ export class IgxListItemComponent implements IListChild {
321321
}
322322
}
323323

324+
/**
325+
* @hidden
326+
*/
327+
@HostListener('pancancel')
328+
public pancancel() {
329+
this.setContentElementLeft(0);
330+
this._panState = IgxListPanState.NONE;
331+
this.hideLeftAndRightPanTemplates();
332+
}
333+
324334
/**
325335
* @hidden
326336
*/

projects/igniteui-angular/src/lib/list/list.component.spec.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,44 @@ describe('List', () => {
594594
expect(rightPanTmpl.nativeElement.style.visibility).toBe('hidden');
595595
}));
596596

597+
it('cancel left panning', fakeAsync(() => {
598+
const fixture = TestBed.createComponent(ListWithPanningTemplatesComponent);
599+
const list = fixture.componentInstance.list;
600+
fixture.detectChanges();
601+
602+
const firstItem = list.items[0] as IgxListItemComponent;
603+
const leftPanTmpl = firstItem.leftPanningTemplateElement;
604+
const rightPanTmpl = firstItem.rightPanningTemplateElement;
605+
const itemNativeElements = fixture.debugElement.queryAll(By.css('igx-list-item'));
606+
607+
/* Pan item left */
608+
cancelItemPanning(itemNativeElements[1], -2, -8);
609+
tick(600);
610+
611+
expect(firstItem.panState).toBe(IgxListPanState.NONE);
612+
expect(leftPanTmpl.nativeElement.style.visibility).toBe('hidden');
613+
expect(rightPanTmpl.nativeElement.style.visibility).toBe('hidden');
614+
}));
615+
616+
it('cancel right panning', fakeAsync(() => {
617+
const fixture = TestBed.createComponent(ListWithPanningTemplatesComponent);
618+
const list = fixture.componentInstance.list;
619+
fixture.detectChanges();
620+
621+
const firstItem = list.items[0] as IgxListItemComponent;
622+
const leftPanTmpl = firstItem.leftPanningTemplateElement;
623+
const rightPanTmpl = firstItem.rightPanningTemplateElement;
624+
const itemNativeElements = fixture.debugElement.queryAll(By.css('igx-list-item'));
625+
626+
/* Pan item right */
627+
cancelItemPanning(itemNativeElements[1], 2, 8);
628+
tick(600);
629+
630+
expect(firstItem.panState).toBe(IgxListPanState.NONE);
631+
expect(leftPanTmpl.nativeElement.style.visibility).toBe('hidden');
632+
expect(rightPanTmpl.nativeElement.style.visibility).toBe('hidden');
633+
}));
634+
597635
it('checking the header list item does not have panning and content containers.', () => {
598636
const fixture = TestBed.createComponent(ListWithPanningTemplatesComponent);
599637
const list = fixture.componentInstance.list;
@@ -818,6 +856,19 @@ describe('List', () => {
818856
});
819857
};
820858

859+
const cancelItemPanning = (itemNativeElement, factorX, factorY) => {
860+
itemNativeElement.triggerEventHandler('panstart', {
861+
deltaX: factorX
862+
});
863+
itemNativeElement.triggerEventHandler('panmove', {
864+
deltaX: factorX,
865+
deltaY: factorY,
866+
additionalEvent: 'panup'
867+
});
868+
869+
itemNativeElement.triggerEventHandler('pancancel', null);
870+
};
871+
821872
const clickItem = (currentItem: IgxListItemComponent) => Promise.resolve(currentItem.element.click());
822873

823874
const verifyItemsCount = (list, expectedCount) => {

0 commit comments

Comments
 (0)