Skip to content

Commit

Permalink
Merge pull request #3470 from IgniteUI/sstoychev/s-next-prev-cons-master
Browse files Browse the repository at this point in the history
Preventing wrap-around for scrollNext and scrollPrev -- MASTER
  • Loading branch information
mpavlinov authored Dec 19, 2018
2 parents 1ba2d4e + d18970e commit 5223b84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ describe('IgxForOf directive -', () => {
await wait(1500);
fix.detectChanges();
const scrStepArray = fix.componentInstance.parentVirtDir.scrStepArray;
expect(scrStepArray.length).toEqual(61);
expect(scrStepArray.length).toBeGreaterThan(55);

// check if inertia first accelerates then decelerate
const first = scrStepArray[0];
Expand Down Expand Up @@ -794,6 +794,22 @@ describe('IgxForOf directive -', () => {
}
});

it('should not wrap around with scrollNext and scrollPrev', async () => {
const forOf = fix.componentInstance.parentVirtDir;
forOf.scrollPrev();
fix.detectChanges();
await wait(200);
expect(forOf.state.startIndex).toEqual(0);
forOf.scrollTo(forOf.igxForOf.length - 1);
fix.detectChanges();
await wait(200);
expect(forOf.state.startIndex).toEqual(forOf.igxForOf.length - forOf.state.chunkSize);
forOf.scrollNext();
fix.detectChanges();
await wait(200);
expect(forOf.state.startIndex).toEqual(forOf.igxForOf.length - forOf.state.chunkSize);
});

it('should prevent scrollTo() when called with numbers outside the scope of the data records.', () => {
fix.componentInstance.parentVirtDir.testScrollTo(-1);
expect(fix.componentInstance.parentVirtDir.state.startIndex).toBe(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
* @param index
*/
public scrollTo(index) {
if (index < 0 || index > (this.isRemote ? this.totalItemCount : this.igxForOf.length)) {
if (index < 0 || index > (this.isRemote ? this.totalItemCount : this.igxForOf.length) - 1) {
return;
}
const containerSize = parseInt(this.igxForContainerSize, 10);
Expand Down

0 comments on commit 5223b84

Please sign in to comment.