Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preventing wrap-around for scrollNext and scrollPrev -- MASTER #3470

Merged
merged 4 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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